It beeps!

I have discovered a new definition for the word frustration.  It goes by the name of a sound ring-buffer.

Driving the sound on the DS is pretty straightforward.  Its simply a case of setting up a sound channel and pointing it to a buffer that holds your sound data.  This works perfectly for playing pre-defined samples.  However, when attempting to stream sound data by creating and playing samples continuously the DS starts struggle.  This causes popping and cracking in the sound.

One method to get around this problem is the use of a ‘ring-buffer’.  The theory involves creating an empty sample that is played in a continuous loop.  The current play position of this empty sample is tracked using a timer.  When a new section of sound data needs to be played it is mixed into the empty sample just ahead of the current play posision.

As far as the hardware is concerned, it is just playing one sample over and over again, but it means that it is posible to alter the sample with the new data being streamed in.

The theory doesn’t sound too bad.  It is, however, very dependent on timing.  If the new sound data is mixed in too slowly, the play position of the buffer will catch up and eventually override the newly mixed data.  If the new sound data is mixed in too quickly, the mix position will wrap around the buffer and override the data currently being played.

I have had major problems getting the timing to be perfect.  I must have redesigned and wrote the sound code 6 or 7 times over the last few weeks without any real success.

Anyway, on Monday I had a bit of free time so a sat down and rewrote it again from scratch.  Its the closest i’ve been so far, and sounds pretty good.  The mix position is still running slightly quicker than the play position, but if it runs too far forward I skip a sample until it catches up.  This can cause the odd scratch in the sound, but it only appears noticable when playing a fixed tone (using the BASIC beep command for example).

This whole problem does indicate that either the CPU core is running too fast or the sound is running too slow.  At the moment I think its good enough to put into the first release and am going to move back to the file browser.  Once i’ve cleaned it up a bit I think we are looking good for a release of Version 0.1.


9 comments so far

  1. Bart on

    Great news, I hope to play Alien8 soon 😎

    Keep up the great work

  2. Drood on

    KEEP UP THE GOOD WORK! Really appreciate your work on this. I look forward to being able to play… Well, many Speccy classics (and not so classics) on my M3!

    One question: How are you storing the snapshots? Directory? Compiled into a rom? (Like the GBA Speccy emulator was if I recall.) Just wondered what sort of directory structure we’ll be using.

  3. CraigT on

    Hi Drood.

    There isn’t any need to append or inject spectrum snapshots into the SpeccyDS rom. You just need to copy the files onto your flash card. The file browser will then let you view and select the .SNA files you want to load. There are still a few little bugs with navigating around folders and I need to clean the graphics up a bit before the first release.

    I am using Chishm’s gba_nds_fat library ( to handle all my file access. The library works with a wide range of homebrew methods (including the M3!) so compatibiliy should be quite good.

  4. thehive on

    My offer of help with the audio still stands you know! 🙂

  5. CraigT on

    Thanks TheHive. I do appreciate the offer 🙂 I was very close to mailing you about it a couple of weeks back, but I was determined to get it working myself. I think i’ve almost got it cracked now.

  6. daninski on

    *beep-beep* i want some beeps too!

  7. spam on

    Oi Hive *cracks whip* get back to dspec or you’re going to your room without supper!

  8. siccoyote on

    Keep up the good work, hope you manage to crack it!

  9. shayman on

    I’m thinking of doing a DS amstrad-cpc emulator, so I was interested to read that you converted the z80 core into assembler – this worries me slightly as I know very little about the ARM chip (although my z80 is top drawer, that won’t exactly help!)
    Was perfromance that bad with the z80 core in C ?
    Keep up the good work btw, any info on a first release?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: