Hey,
I was out of town for a few days and had a couple boring nights in a hotel room, so I decided to see about playing wav files, for voice and stuff (not for music or most sound effects, since it’s very space hungry and inefficient to write each sample… plus the sound quality isn’t great since it’s not meant to be done).
Anyway, attached is a quick demo of the VB driver side… the app plays once, then waits for a keypress to replay. I manually converted the wav file w/ MATLAB, but I’ll be writing a standalone app to do the conversion soon (hopefully).
DogP
Attachments:
Okay… I got the wav conversion app written… I’ll clean everything up and post it tomorrow night.
DogP
Ime Wario, Ime gonna wine! Very nice, a great achievement! π
Can the scratchy background noise be filtered out somehow or is it unavoidable?
I’m not sure… there may be something that can be done, although if you listen to speech in the commercial games, there’s some scratchiness there, so I’m not too optomistic about it. There may be a trick I can do using multiple channels to get more resolution… currently I’m using just a single channel, so I’ll look at the raw waveform on an oscilloscope and see if I can smooth it out.
BTW, attached is one I did completely using the converter. Just press a button to go through the different ones (it just goes through an assortment of sounds).
DogP
Attachments:
All those Mario Kart sounds make me dream about a new version of Virtual Cup. π
Does the sound data need so much space or is the ROM padded to 1 MB?
Oh… it’s just padded, since my flash cart I usually use is 1MB. The data is 11025 samples/sec, and each sample is 4 bits, so it’s a little over 5KB per second. The first Wario one was only 6400 samples/sec, which is only 3.2KB per second. Stereo of course doubles that (the last sound on the second ROM was stereo), and I was doing some thinking on how I could make it sound better, and I may be able to do some tricks to make it more than 4 bits per sample. It’ll take up more space, but should sound much better. V1 will be just what you see here though… for V2 I’ll try some new tricks.
Heh, and yeah, the Kart sounds are some convenient wavs I had laying around from when I was working on my other converter, which as you can tell, didn’t sound nearly as good as this one does. I’ll have to convert the “Mario Kart Virtual Cup” sound to do a side by side comparison.
DogP
Okay… attached is v1.0 of wav2vb and the wavonvb sample. It’s pretty self explanatory, but basically just do wav2vb
The wav player (wavonvb) basically initializes the sound for speech, then calls a function that writes (and blocks) until the wav data is written. This could probably be done with an interrupt on a timer if you wanted speech without a blocking call. There’s a #define called SR_DIV, which defines the delay numerator to be divided by the sample rate of the wav file, but it’s not perfect, so it’ll likely need to be tweaked, depending on the sample rate (it only affects the delay in the loop, neglecting the time to actually execute the sound writing).
I’m sure there’s plenty of bugs, but it’s been working for me… but let me know if you have any problems, or feature requests for the next version. I’ll probably try to get more resolution for the next one, which should help the sound quality, but take up more ROM space.
DogP
Attachments:
Heh, this seems to be a very popular thread π . Anyway, for those that don’t have the hardware to try it out, or are just too lazy (I don’t blame you… by itself, the demo is nothing exciting), here’s a wav recording of it. Unfortunately, with how Allegro handles sound, I don’t think RB will ever be able to play this kind of sound without a complete sound processor rewrite.
On an unrelated note… in the long term, I think that’s exactly what RB needs, since the currently unsupported modes are likely going to stay that way since Allegro can’t natively support them (easily at least)… but I definitely don’t feel like writing a sound core for it.
Oh… I’m not sure if I ever explained the idea of making this work. Basically, I load the waveform RAM with a DC value of max amplitude. This by itself this creates no sound. How it creates the sound is by using the volume control of the channels to write the amplitude of the sample, in effect creating the AC waveform. Unfortunately, there’s only 4 bits of amplitude, so you don’t have a lot of resolution. The output is AC coupled, so I use an amplitude of 8 as my 0, and swing +/- from there.
More resolution should be possible by using a second channel with a lower amplitude DC value in waveform RAM (using two waveforms and channels rather than one). If you make it a ratio of 16:1, you could actually get 8 bits (upper 4 bits on waveform 1, lower 4 bits on waveform 2), but unfortunately the waveform RAM is only 6 bits (0-63), so that’d mean your second waveform would only be a value of 3.
This may or may not be too small to make a difference (I dunno if too much resolution will be lost in the output calculation). It’s worth a try, and if that doesn’t work, you could use more channels of equally weighted amplitude to double the resolution for each channel added (5 channels w/ equal waveform would give 8 bits). That is a simple solution, but wastes channels, so no music could be playing while the wav is playing.
DogP
Attachments:
Wow, that sounds really good! I have been watching threads like this, but have not downloaded stuff or commented being I am not ready to use things like this (I am focusing on different things right now). But I promise, I, and probably a lot of other people, are interested, we just have nothing to say!
Gee, I guess I’m the first one to try this out. I used this program to get an .h file from a .wav file. Now, what is the proper C code to get this to play in my program?
Heh… good to see someone try it out π . For playing the file, look at the wavonvb zip file. The stuff in wavonvb.c above main() should be copied to your main program, call init_speech() from your program, and then where you want to play a wav file, call the wavplay function like in the main function of wavonvb.c. Of course you’ll need to change the #include to match the .h you created.
DogP
Where it should play the sound, it just flashes white (with no SFX). It does the same thing in your sample program (although the white screen is steady.) I’m playing this with Reality Boy, and the sound works fine on the other programs I have.
I’ve got an idea that I could use this for. I just have to modify wavplay() to support pitch-bending…
Also, @VirtualChris:
DogP wrote:
Unfortunately, with how Allegro handles sound, I don’t think RB will ever be able to play this kind of sound without a complete sound processor rewrite.
Yeah, you don’t need the:
while(!(vbReadPad()&K_ANY));
or
VIP_REGS[BKCOL]^=3;
I just put those in my sample code to wait for a keypress to start the next sound, and then toggle the background color (so I could see whether it was actually trying to go to the next sound).
And yeah… it doesn’t work in RB… you need to test it on real hardware.
DogP
No… the VB isn’t really meant to do any PCM… I’m basically rigging it to do 4-bit PCM by giving it a DC waveform and manually adjusting the volume to create the sample. There’s no DMA and you can’t queue up a “wav file”, so you have to use CPU cycles to manually write each sample. Because of that, it’s really only good for effects like intro speech and stuff, when you don’t care about CPU time.
The VB audio is meant to play similar to a MIDI, where you give it a waveform and a frequency and it plays that note until told to do differently (or if an effect like ramp/sweep/modulation/etc is used).
DogP
Sorry to necropost here, but I forgot how to use this. The name of the file is aah.wav, right, so I type in wav2vb
“<" and ">” are reserved characters in the command-line. The help for the program uses them to show the placeholders you replace with filenames. Just use your filename as-is, like:
wav2vb.exe ahh.wav ahh.h
Making sure, of course, that ahh.wav is in the same folder as the exe, or else specifying its full path like this:
wav2vb.exe c:\somefolder\ahh.wav c:\somefolder\ahh.h
And if there are spaces in the name or path, enclose it in double quotes (“).
Was just wondering if there was a way to make it do something while the wav is playing. Right now it pauses everything while the wav sound is playing.
VirtualChris wrote:
Was just wondering if there was a way to make it do something while the wav is playing. Right now it pauses everything while the wav sound is playing.
Not the way it’s currently written, but you could, as long as you have some way to update the sound at the desired sample rate.
The sample used a 11025 Hz sample rate, which means it has to be updated approximately every 90 microseconds. That’s about 1800 CPU cycles, which you can handle yourself, or set up a timer interrupt. You could also use a lower sample rate to increase the amount of time.
I wouldn’t recommend playing WAVs as your main method of sound though… I imagined using it like the commercial games do… as a special effect during unimportant parts, like “Good Luck” or “Welcome to Space World, Lets Go!” (or whatever they say).
DogP