Click here to Skip to main content
15,890,506 members
Home / Discussions / C#
   

C#

 
AnswerRe: Insert Image in toolstrip ( win app ) Pin
Ennis Ray Lynch, Jr.5-Aug-10 4:15
Ennis Ray Lynch, Jr.5-Aug-10 4:15 
GeneralRe: Insert Image in toolstrip ( win app ) Pin
Krishna Varadharajan5-Aug-10 20:03
Krishna Varadharajan5-Aug-10 20:03 
QuestionConnection Level in Compact Framework Pin
Tyler455-Aug-10 2:23
Tyler455-Aug-10 2:23 
QuestionWave files Pin
V.5-Aug-10 1:21
professionalV.5-Aug-10 1:21 
AnswerRe: Wave files Pin
Bernhard Hiller5-Aug-10 1:45
Bernhard Hiller5-Aug-10 1:45 
GeneralRe: Wave files Pin
V.5-Aug-10 2:00
professionalV.5-Aug-10 2:00 
GeneralRe: Wave files Pin
OriginalGriff5-Aug-10 2:03
mveOriginalGriff5-Aug-10 2:03 
GeneralRe: Wave files Pin
V.5-Aug-10 2:14
professionalV.5-Aug-10 2:14 
MMM, I don't think so, the entire thing is written to file as a byte array (logical, it's a binary file Wink | ;-) , but only when all else is set.
Here's the code:

public void PlayNoteWav(string note, int position)
{

    //I think the hardware only allows one beep at the time.
    //I would need to find a way to 'produce' a sound via the speakers instead of via a beep.
    //http://naudio.codeplex.com/
    //http://www.csharp-home.com/index/tiki-read_article.php?articleId=105
    //DIrectSound?
    Dictionary<int, double> played_note = guitar_strings[note];
    if (position >= 0)
    {
        double frequency = played_note[position];
        CreateWaveFile(frequency, duration);
    }                                               //end if
    else
    {
        System.Threading.Thread.Sleep(duration);
    }                                               //end if
}

public void CreateWaveFile(double frequency, int duration)
{
    bool whiteNoise = false;
    Random rand = new Random();

    file = new WaveFile(2, 16, 44100);

    int samples = 44100; //Creates 1 second of audio


    // Sound Data Array
    // Size needs to be :
    //          Number Of Channels - 1 for mono
    //                               2 for stereo
    //          Bits Per Sample    - How many bits are used to describe each Sample
    //          Samples            - How many samples that are provided
    //
    // Sound Data Size = Number Of Channels * Bits Per Sample * Samples

    /*  f:x -> a*sin(b*(x-c)) + d
     * a = amplitude
     * b = frequency
     * c = phase
     * d = move up/down Y-axis
     */

    byte[] data = new byte[file.NumChannels * (file.BitsPerSample / 8) * samples];

    if (whiteNoise)
    {
        //Creates White Noise
        for (int i = 0; i < data.Length; i++)
        {
            data[i] = (byte)rand.Next(256); //256 is the max size of a byte
        }
    }
    else
    {
        //Creates a Constant Sound
        for (int i = 0; i < data.Length; i++)
        {
            data[i] = (byte)(256 * Math.Sin(1/frequency * i));
        }
    }
    file.SetData(data, samples);
    file.WriteFile(@"C:\Test.wav"); //Writes the wave file out to the destination given
}


Generally in the background it will hold all the information before writing to file.
Doesn't this statement:
byte[] data = new byte[file.NumChannels * (file.BitsPerSample / 8) * samples];<br />
take in account 16 bit sound (if bitspersample is set to 16) ?

In any case I'll have a go with setting to 8 bits mono, just for testing.

thanks.
V.

GeneralRe: Wave files Pin
OriginalGriff5-Aug-10 2:24
mveOriginalGriff5-Aug-10 2:24 
AnswerRe: Wave files Pin
Luc Pattyn5-Aug-10 2:41
sitebuilderLuc Pattyn5-Aug-10 2:41 
GeneralRe: Wave files Pin
V.5-Aug-10 3:07
professionalV.5-Aug-10 3:07 
GeneralRe: Wave files [modified] Pin
Luc Pattyn5-Aug-10 3:29
sitebuilderLuc Pattyn5-Aug-10 3:29 
GeneralRe: Wave files Pin
DaveyM695-Aug-10 3:47
professionalDaveyM695-Aug-10 3:47 
GeneralRe: Wave files Pin
Luc Pattyn5-Aug-10 3:58
sitebuilderLuc Pattyn5-Aug-10 3:58 
GeneralRe: Wave files Pin
V.5-Aug-10 21:04
professionalV.5-Aug-10 21:04 
QuestionSocket Connection Pin
Agweet4-Aug-10 22:46
Agweet4-Aug-10 22:46 
AnswerRe: Socket Connection Pin
freakyit5-Aug-10 1:54
freakyit5-Aug-10 1:54 
AnswerRe: Socket Connection Pin
Ennis Ray Lynch, Jr.5-Aug-10 2:27
Ennis Ray Lynch, Jr.5-Aug-10 2:27 
AnswerRe: Socket Connection Pin
Member 7906565-Aug-10 2:28
Member 7906565-Aug-10 2:28 
GeneralRe: Socket Connection Pin
Agweet5-Aug-10 3:58
Agweet5-Aug-10 3:58 
QuestionHow to Call a Server side Function on the Client side Pin
Vimalsoft(Pty) Ltd4-Aug-10 22:04
professionalVimalsoft(Pty) Ltd4-Aug-10 22:04 
AnswerRe: How to Call a Server side Function on the Client side Pin
Prosanta Kundu online4-Aug-10 22:40
Prosanta Kundu online4-Aug-10 22:40 
GeneralRe: How to Call a Server side Function on the Client side Pin
Vimalsoft(Pty) Ltd4-Aug-10 23:52
professionalVimalsoft(Pty) Ltd4-Aug-10 23:52 
GeneralRe: How to Call a Server side Function on the Client side Pin
Pete O'Hanlon5-Aug-10 0:07
mvePete O'Hanlon5-Aug-10 0:07 
GeneralRe: How to Call a Server side Function on the Client side Pin
Vimalsoft(Pty) Ltd5-Aug-10 0:16
professionalVimalsoft(Pty) Ltd5-Aug-10 0:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.