Previous Thread
Next Thread
Print Thread
Joined: Sep 2011
Posts: 4
E
emit Offline OP
Member
OP Offline
Member
E
Joined: Sep 2011
Posts: 4
I'm attempting to port nestopia to a new platform but the sound module is giving me problems. This is primarily because I've never worked with low level sound...

The way I ported the graphics module was simply through Video::Output::lockCallback.Set() and utilizing the pixels buffer on unlock.

I figured sound would work in a similar manner but I'm not sure what kind of data I'm getting in Sound::Output samples[0]/length[0]. I thought it might be raw/pcm so I dumped it to a file and tried playing in raw mode with aplay but it appears to be a constant tone.

these are the sound settings i'm using:

Sound sound(_emulator);
sound.SetSampleBits(16);
sound.SetSampleRate(22050);
sound.SetSpeaker(Sound::SPEAKER_MONO);
sound.SetVolume(Sound::ALL_CHANNELS, 80);

(attempted to play dump with aplay -c 1 -f U16_LE -r 22050)
i've set length[0] to 22050/60 and confirmed it's running the callback every ~16ms. Any hints?

I've studied the two ports, i.e. for linux and osx, but neither one seems to make use of the soundLock/unlock callbacks registered with Sound::Output::lockCallback.Set() and unlockCallback.Set().

BTW, the nestopia code is very beautiful. I've ported fceux to this platform as an exercise very easily but the code is the ugliest pile of crap i've encountered.

Joined: Mar 2001
Posts: 16,919
Likes: 57
R
Very Senior Member
Online Content
Very Senior Member
R
Joined: Mar 2001
Posts: 16,919
Likes: 57
samples[0] should be set to the pointer to your audio output buffer. You'll get samples[1] samples (raw signed 16-bit PCM) each time a frame runs.

Joined: Sep 2011
Posts: 4
E
emit Offline OP
Member
OP Offline
Member
E
Joined: Sep 2011
Posts: 4
thank you for your reply.

I have samples[0] set to my static buffer and length[0] set to 22050/60 once during initialization. However, I've had samples[1] set to NULL and length[1] to 0, modeled after the linux port.

So instead, I should actually use samples[1] and not samples[0] if I want raw pcm? I will give it a shot and report back.

I'm still studying the audio renderer and related code but the use of streams and templates make it look greek to me so far laugh Still very nice to look at

Joined: Mar 2001
Posts: 16,919
Likes: 57
R
Very Senior Member
Online Content
Very Senior Member
R
Joined: Mar 2001
Posts: 16,919
Likes: 57
No, typo on my part. samples[1]/length[1] can be left at NULL/0, that's fine.

Joined: Sep 2011
Posts: 4
E
emit Offline OP
Member
OP Offline
Member
E
Joined: Sep 2011
Posts: 4
perfect, I got it. I had it set up correctly with the sound lock and unlock but I was dumping &(sound.samples[0]) not sound.samples[0] haha....


Joined: Mar 2001
Posts: 16,919
Likes: 57
R
Very Senior Member
Online Content
Very Senior Member
R
Joined: Mar 2001
Posts: 16,919
Likes: 57
Nice. What are you porting to?

Joined: Sep 2011
Posts: 4
E
emit Offline OP
Member
OP Offline
Member
E
Joined: Sep 2011
Posts: 4
palm webOS. i got one of those discontinued & discounted touchpads a few days ago so i thought i would mess around with it a little. the port will be free and gpl when it's done.

btw, when I dump the samples sequentially to a raw pcm file and play it, it's smooth... however, while in the emulator there is an issue with the rates at which the lock/unlock is producing samples and my consumer reading the data for pcm output.

On each soundlock, my sound.samples[0] is set to point to a section of a large circular buffer. Basically n bins of 367 samples and the current bin pointers rotates around.

With a 50ms lag (arbitrarily picked..), a consumer transfers small chunks of the buffer to pcm out. This consumer should read samples at 22050Hz, but somehow I think the consumer is overtaking the producer after which the consumer needs to lap the producer to resync...

does it matter that 22050Hz at 60fps technically needs 367.5 samples per frame? do i need to insert an extra sample every other frame to reduce sync issues?


edit: sorry, the sync issue was just my stupidity. i'm still curious if i should feed an extra sample every other frame

Last edited by emit; 09/14/11 06:11 PM.

Moderated by  Marty, R. Belmont 

Link Copied to Clipboard
Who's Online Now
2 members (Duke, Richard Bannister), 25 guests, and 12 robots.
Key: Admin, Global Mod, Mod
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Forum Statistics
Forums9
Topics9,100
Posts119,237
Members5,019
Most Online890
Jan 17th, 2020
Our Sponsor
These forums are sponsored by Superior Solitaire, an ad-free card game collection for macOS and iOS. Download it today!

Superior Solitaire
Forum hosted by www.retrogamesformac.com