#117189 - zohar - Fri Feb 02, 2007 4:18 am
From libnds, TransferSoundData(..) will allow you to adjust the frequencies of audio files. Raising the frequency of a sample will increase its pitch and also speed up its total playtime.
Of course, this is what it is supposed to do--but, is there any way to raise the pitch of a sound effect without affecting its length? Has anyone written any expanded sound functions beyond the limited TransferSoundData(..)?
#117202 - HyperHacker - Fri Feb 02, 2007 9:51 am
This frequency change is handled in hardware, changing the rate it reads the sound data. Suppose you want to double the pitch, then you need to double the length too since the same amount of data now creates a sound half as long. You could do this by doubling the data itself; read one byte/word/whatever size you're using from the file, and write it twice into memory (01 02 03 becomes 01 01 02 02 03 03). However a more efficient way would probably be just to change the pitch in software as you read it (01 02 03 becomes 02 04 06).
I hope this is right, anyway, because I've never done it myself. ^_^;
_________________
I'm a PSP hacker now, but I still <3 DS.
#117211 - 0xtob - Fri Feb 02, 2007 11:27 am
Well, It's not that easy unfortunately.
Quote: |
You could do this by doubling the data itself; read one byte/word/whatever size you're using from the file, and write it twice into memory (01 02 03 becomes 01 01 02 02 03 03). |
This would actually have the same effect as dividing the sampling rate by two, i.e. the sample gets twice as long and the pitch gets lower.
Quote: |
However a more efficient way would probably be just to change the pitch in software as you read it (01 02 03 becomes 02 04 06). |
This would increase the amplitude of the signal, and wouldn't affect the pitch at all. In PCM waveforms (i.e. the sound data the DS and pretty much everything else uses) the individual values don't mean the pitch but the amplitude of the recorded sound at the given time.
For changing the pitch without affecting the speed, you would have to do some digital signal processing. As always, Wikipedia has a good overview on Pich Shifting. Maybe it's possible to port the SoundTouch library.
_________________
http://blog.dev-scene.com/0xtob | http://nitrotracker.tobw.net | http://dsmi.tobw.net
#117243 - zohar - Fri Feb 02, 2007 8:23 pm
I have some background in DSP so I know I can get pitch-shifting to work on a PC (either via MATLAB or other applications). The problem is... since I'm new to DS programming, I'm not sure how to even start doing this on a DS. How do I even read an audio file's data with devkit? How would I write it back to memory after I've altered it?
#117246 - tepples - Fri Feb 02, 2007 8:52 pm
zohar wrote: |
How do I even read an audio file's data with devkit? |
Use Chishm's libfat and a .wav parser library (which I can provide if you want).
Quote: |
How would I write it back to memory after I've altered it? |
Use Chishm's libfat and a .wav writer library (which I can provide if you want).
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#117289 - zohar - Sat Feb 03, 2007 10:14 am
Yeah, tepples, that would be great. Do you have a link or will you send it via email? Also, I thought DS only takes raw files?
#117318 - tepples - Sat Feb 03, 2007 8:10 pm
zohar wrote: |
Yeah, tepples, that would be great. Do you have a link |
Look in 81 and 8ad.
Quote: |
Also, I thought DS only takes raw files? |
The DS hardware only takes raw files, but your code can load a .wav file from FAT into RAM, invert the most significant bit of each sample to convert unsigned samples to signed samples (if the file's header indicates that the data is 8-bit PCM), and then tell the ARM7 to copy the address, format, rate, and length of the sound data from the file's header into the sound registers.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#117415 - silent_code - Sun Feb 04, 2007 7:59 pm
*OFFTOPIC*
zohar wrote: |
... via MATLAB or ... |
OMFG, MATLAB! now, that's an application i *can't* stand. yeah, it's powerfull and all, but...
#117482 - zohar - Mon Feb 05, 2007 2:14 am
silent_code wrote: |
OMFG, MATLAB! now, that's an application i *can't* stand. yeah, it's powerfull and all, but... |
lol, I was the same way too actually. But after a while, you really have to appreciate everything it does, and how well it does it. It's just ridiculous.