Jump to content

April 2017 »

232425262728 29

Recent Entries

Recent Comments

Recent Entries

Recent Comments

- - - - -

Sound wave generator - quick update

4: Adsense

I tried implementing the sound wave generation looping through hard-coded samples rather than algorithmically, but I have issues with the current implementation. The basic approach is straightforward but it took a couple of days to debug and the result still doesn't sound right. Apart from the output sounding lower quality, it is clearly out of tune. Not sure what is going on there - whether it's a discretisation thing, something with converting floats or merely another bug.

I decided to go with samples because it's very easy to add new wave forms. Create an array of floats for one wave period, plug it in, and you're done. AFAIK its the way sine waves were done in hardware due to how computationally expensive they are to calculate. Plus if I get around to adding normal non-looping sound files to this system it's done in the same way.

My gut feeling is that it is better to go back to implementing the core of this system as if it was on a hardware chip - using simple hard-coded algorithms, different for each tone, based on bit registers with different purpose per waveform - and then add a layer on top of that to convert instructions like "channel 1, triangle wave, 440Hz, half volume" into the right register values.

Eventually I want to play around with phase modulation, like what was used on the Yamaha chips used in Adlib sound cards or the Sega Genesis/Mega Drive, once I get my head around how the operators worked in hardware.

Aug 20 2012 07:28 PM
These days it might be better to just use the sin() function unless you are using huge amounts of wave generators. For a 44.1 kHz sampling rate, that means only 44100 sin() calls per second. This is a small fraction (much less than 1%) of what is possible in real time on current hardware. Unless you're developing for embedded or underpowered systems, I'd stick with generating the waves from scratch, rather than having to generate and then interpolate a wave table.
Aug 21 2012 04:53 AM
The OPL2 chip in Adlib cards used 18 oscillators, each representing a sine wave, and output at nearly 50kHz, so that's approaching a million trig calls a second.

I'm not sure what the speed is of the trig function calls on today's hardware; I'll make a note to check. I don't think it would be a bottleneck if I did use a million trig function calls on today's hardware, but I'd like to compare it with lookup tables regardless to test whether there is a noticeable difference to how it sounds.

Note: GameDev.net moderates comments.