• Creating an audio file
    14 replies, posted
I have a list of time values:[CODE]1 second 1,5 seconds 3 seconds 10 seconds[/CODE] I want to create an audio file (WAV, MP3, anything will do) which has a sound at every time value in the list. The result will be, for example, a single .WAV file that has a beep at 1 second; 1,5 seconds; 3 seconds and 10 seconds.
You could make a simple file which saves those as deltas, then in a thread read one float, sleep that long and Console.Beep(), repeat until EOF. [editline]03:08PM[/editline] If you actually need an audio file, which other audio players can play, [url=http://stackoverflow.com/questions/203890/creating-sine-or-square-wave-in-c]this here[/url] might be worth a look then.
I don't really understand how to make sine waves the length I want, etc. Isn't there a way to "append" an already existing beep WAV file in another longer WAV file, to achieve the result I wrote in the OP?
midi is based on time values...
[QUOTE=Burning Ninja;22726431]midi is based on time values...[/QUOTE] How can I create one? Is there any library I need?
[QUOTE=SupahVee;22726293]I don't really understand how to make sine waves the length I want, etc. Isn't there a way to "append" an already existing beep WAV file in another longer WAV file, to achieve the result I wrote in the OP?[/QUOTE] Probably. But creating the wave form by hand is more pretty :} [cpp]int length = 1; // 1 second int sampleRate = 8000; // 8000 samples per second System.Int16[] buffer = new System.Int16[length * samples]; // System.Int16 -> signed 16 bit audio double amplitude = 0.25 * System.Int16.MaxValue; // 1/4 of maximal amplitude double frequency = 1000; // 1000 oscillations per second (1kHz sound) for (int n = 0; n < buffer.Length; ++n) { buffer[n] = (short)Math.Round(amplitude * Math.Sin((2 * Math.PI * n * frequency) / sampleRate)); // You can simply use a function plotter to see why we do this }[/cpp]
I still do not understand how to use WaveStream, since it's the first time I use NAudio, also, I don't understand how to place the sine waves at specific time intervals as I stated in the OP:
There don't seem to be online docs, but there's a WaveFileWriter-class. So you create a new wave-file with that and use WriteData to write the buffer-array in the wave-file. Silence is just a matter of adding zeros. One second of silence would be 8000 zeros, presuming you use 8000 samples per second like in the snippet.
for one seconds of silence should I write: buffer[n] = 8000? no wait that doesn't make sense i'm really confused, could you make a simple example using time intervals?
I'd actually try to explain what is happening than just giving you a snippet tbh. The sample rate, as chosen in the snippet, is 8000. That means, that for each second there will be 8000 samples. Each samples ranges from -2^16 to 2^16-1, since we're working with signed 16 bit audio. 0 would mean that the membrane of the box is in its original state (whereas the two maximums would mean that the membrane should be fully outward or inwards). As such, for one second you need 8000 samples (16-bit integers) to tell the membrane where it should be. And you want it non-moving in its original state, so there should be 8000 zeros.
So to have a pause lasting a second: buffer[0~8000] = 0; ?
Yes. :3
[QUOTE=ZeekyHBomb;22733406]Each samples ranges from -2^16 to 2^16-1, since we're working with signed 16 bit audio.[/QUOTE] No it isn't? If I'm not completely wrong, it's from -((2^16)/2) to (2^16)/2-1
Still, I'm not sure how to create the loop that would make the beeps appear only in the time intervals. In the snippet you posted before, what should the variables "samples" be?
[QUOTE=esalaka;22734407]No it isn't? If I'm not completely wrong, it's from -((2^16)/2) to (2^16)/2-1[/QUOTE] Indeed. [QUOTE=SupahVee;22734763]Still, I'm not sure how to create the loop that would make the beeps appear only in the time intervals. In the snippet you posted before, what should the variables "samples" be?[/QUOTE] Your samples are in the array. The array should make room for the complete length, so using your info of the OP then the arrays length should be (10 + beeplength) * sampleRate.
Sorry, you need to Log In to post a reply to this thread.