It is currently Mon Dec 11, 2017 2:10 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Wed Mar 23, 2016 3:41 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
How can I confirm the emulator sound output pitch is correct?


Top
 Profile  
 
PostPosted: Wed Mar 23, 2016 4:39 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19329
Location: NE Indiana, USA (NTSC)
Are you referring to the pitch of the generated waveform relative to the sample rate, or the sample rate that the operating system is actually using relative to the sample rate that you specified when opening an audio stream for output? For the former, you can add a feature to log sound output to a .wav file, and then count how many samples it takes for the waveform to rise and fall a given number of times. For the latter, you may have to use operating-system-specific APIs to determine the playback state of an output voice.

Or are you referring to conversion of tone generator parameters to a musical pitch in A440 equal temperament tuning?


Top
 Profile  
 
PostPosted: Wed Mar 23, 2016 6:52 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
I mean the resample method. According to my notes, the exact sample rate of the NES audio DAC itself is 39375000/22 Hz = 1.7898 MHz. So, I did some math...
Code:
resample to PC 48MHz, but assuming values in Hz:

(39375000 / 22) / 48000 =
= 39375000 / 48000*22 =
= 393750 / 480*22 =
= 393750 / 10560 =
= 39375 / 1056 = 37.286 samples per sync.
DIV 3 => **13125 / 352**

At every CPU cycle, the APU generates a sample.
Code:
const total_samples = 13125;
int divisor = 352;

//at every update:
sample_counter -= divisor;
sample_adder += generated_APU_sample;
num_updates++;
if(sample_counter <= 0) {
   sample_counter += total_samples;
   apu_output_sample = sample_adder / num_updates; //usually, 37 updates.
   sample_adder = 0;
   num_updates = 0;
}

Looks correct, but I sense a bit high pitched... probably because of my... headphones?


Top
 Profile  
 
PostPosted: Wed Mar 23, 2016 7:26 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5886
Location: Canada
Headphones shouldn't by themselves be able to change the pitch of anything.

The rates of everything on the Wiki are correct, AFAIK. How are you comparing your pitch?


Top
 Profile  
 
PostPosted: Wed Mar 23, 2016 9:13 pm 
Offline

Joined: Thu Aug 20, 2015 3:09 am
Posts: 295
I get the same values for the CPU clock rate and resampling ratio for output to 48 kHz.

Dumb question, but are you accounting for the APU square running at half the clock rate? That would make the output one octave too high.
Alternatively, playing a PAL or Dendy ROM at NTSC rate would also raise the pitch.


Top
 Profile  
 
PostPosted: Wed Mar 23, 2016 11:51 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
Approaching it from a stupid end-user POV, three things:

1. If something sounds off, I can record audio from an actual NTSC NES if you need it for comparison -- just let me know which game (ROM filename would be great) and part of the game and I can get you a .zip of 44 or 48kHz 16-bit WAV of whatever's relevant.

2. I have actually encountered audio drivers which have incorrectly done some portion of their mixing -- but ONLY when using MME with 44kHz 16-bit audio files (11kHz and 22kHz were fine, and DirectSound was fine) -- resulting in audio that sounded off by about half an octave. Issue was 100% reproducible using Audacity by switching between MME and DirectSound, and was not specific to Audacity (i.e. mIRC notification audio is where I first noticed the problem). Switching to another sound card resolved the issue. I used to have actual Stereo Mix/WhatUHear recordings of the bug, but I can't find the dang files...

3. ...Rahsennor covered PAL and Dendy. :D


Top
 Profile  
 
PostPosted: Thu Mar 24, 2016 7:48 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19329
Location: NE Indiana, USA (NTSC)
koitsu wrote:
Approaching it from a stupid end-user POV, three things:

1. If something sounds off, I can record audio from an actual NTSC NES if you need it for comparison

Another thing to try is a test ROM that generates a known pitch, such as the 125, 250, 500, 1000, and 2000 Hz beeps in 240p test suite. I too can provide recordings from an NTSC NES.


Top
 Profile  
 
PostPosted: Thu Mar 24, 2016 2:18 pm 
Offline
Formerly Fx3
User avatar

Joined: Fri Nov 12, 2004 4:59 pm
Posts: 3076
Location: Brazil
Rahsennor wrote:
Dumb question, but are you accounting for the APU square running at half the clock rate? That would make the output one octave too high.


Hmm... it makes sense, but the things here are NOT so high pitched - it's slightly off. So, the math must be redone for HALF CPU clock rate.


Top
 Profile  
 
PostPosted: Thu Mar 24, 2016 3:33 pm 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3967
How about recordings or something? They don't need to be pristine or anything, even a cell phone held up to headphones is probably good enough.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Google [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group