Okay, so my previous post got deleted somehow.
So, I took someone's advice, never got the chance to thank them. It worked out
I figured out
wave_length = sample_rate / frequency;
That's pretty streight forward, makes sense to me.
Now, I'm having a problem with audio streams.
I create the stream and then here's how I'm filling it up
| 1 | #define SAMPLE_RATE 22000 |
| 2 | #define FREQUENCY 440.00 |
| 3 | |
| 4 | int i; |
| 5 | unsigned char *stream; |
| 6 | double saw; |
| 7 | double saw_speed; |
| 8 | double wavelength; |
| 9 | double half_wavelength; |
| 10 | AUDIOSTREAM *audio_buffer; |
| 11 | |
| 12 | audio_buffer = play_audio_stream( BUFFER_SIZE, 8, FALSE, |
| 13 | FREQUENCY, 255, 128 ); |
| 14 | wavelength = (SAMPLE_RATE/FREQUENCY); |
| 15 | half_wavelength = wavelength/2; |
| 16 | saw_speed = 255.00/half_wavelength; |
| 17 | |
| 18 | for(;;){ |
| 19 | stream = get_audio_stream_buffer( audio_buffer ); |
| 20 | if ( stream != NULL ){ |
| 21 | for ( i = 0; i < BUFFER_SIZE; i++ ){ |
| 22 | saw += saw_speed; |
| 23 | if ( saw > 255 ){ |
| 24 | saw_speed *= -1; |
| 25 | saw = 255-(saw-255); |
| 26 | } |
| 27 | if ( saw < 0 ){ |
| 28 | saw_speed *=-1; |
| 29 | saw = 0-saw; |
| 30 | } |
| 31 | stream<i> = (unsigned char)saw; |
| 32 | } |
| 33 | free_audio_stream_buffer( audio_buffer ); |
| 34 | } |
| 35 | } |
I'm not sure if the code above compiles and works, it's just a demonstration of what I'm doing. Okay, so...
It plays an A, but it's all choppy as if I'm not fully filling up the audio buffer. But clearly it says "play_audio_stream( BUFFER_SIZE... )" and "for ( i = 0; i < BUFFER_SIZE; i++ )" note usage of BUFFER_SIZE.
Thoughts?
Hmm... Allegro.cc has been acting very strange on me as of late. Failing to post, hiding threads, etc...
Anyhow, it sounds like I'm not filling the buffer up completely. There's a little jitter in the note. The funny thing is, if I play - I think - a 'D', it sounds smooth, and that's it. No idea why.
Thanks again Miran for your help, your advice was perfect despite the small calculation error, I figured it out anyhow. (I seem to remember posting this comment earlier, but it never got posted).
Edit:
I think I may have figured it out. I was resetting the saw on every 'fill'
Thanks guys.
I think I may have figured it out. I was resetting the saw on every 'fill'
Yeah, when you get to the next buffer, you need to continue from whereyou left off the last time.
Perhaps you clicked 'hide thread' by mistake.