![]() |
![]() |
#1 |
AMOS Extensions Developer
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 43
Posts: 1,924
|
Playing samples
Hi,
I am trying to add a few sound samples to my demo, but I am having trouble calculating the period. I believe I have the correct formula (below), but my results (also below) give me the result of 30 - this gives a short high pitched noise. A period value around 200 gives a better sounding result, but doesn't help me to calculate the proper value for this sample (and other samples). Code:
Formula for calculating the period period = frequency (Hz) / (1/sample length (bytes) ) -------------------------------------------- 0.281937 (PAL) microseconds per interval 0.279365 (NTSC) My calculations period = ( 11025 / 0.0001303 ) / 0.281937 = ( 11025 / 1303 ) / 0.281937 = 30 The sample should be played at 11025Hz and is 7673 bytes long. Regards, Lonewolf10 |
![]() |
![]() |
#2 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,268
|
For PAL the period is 3546895 / frequency in Hz / length in bytes, and for NTSC you use 3579545.
Samples have to be an even number of bytes in length, and there's a lower limit of about 125 for the period value (for NTSC and PAL at least). |
![]() |
![]() |
#3 |
2 contact me: email only!
![]() Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,170
|
Here's a little from Mapping the Amiga:
Most sound-digitizing software specifies the waveform frequency by the number of samples per second, not by the period value that the Amiga's hardware expects. The equation for converting the samples-per-second to period value is: Period = 3579564 / Samples-Per-Second So, if you want to play a sound that was sampled at 12 kHz, use a period value of 3579546 / 12000 = 298 To calculate the period value for a note, use the equation Period = 3579546 / (Length * Frequency) where Length is the size of the waveform in bytes and Frequency is the note's frequency value obtained from the table: A = 440 A# or Bb = 466 B = 494 C = 523 C# of Db = 554 D = 587 D# or Eb = 622 E = 659 F = 699 F# or Gb = 740 G = 784 G# or Ab = 831 To raise a note by an octive, divide the period value by 2. It also states the lowest value you should ever use is 124, since this is about as fast as the Amiga can go. If you use a value less than 124, you run the risk of having the same 2 bytes of data output twice in a row. |
![]() |
![]() |
#4 |
AMOS Extensions Developer
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 43
Posts: 1,924
|
Thanks guys, that makes sense
![]() Page 138 of the hardware manual is a little confusing and I ended up using the clock interval instead of the clock constant! ![]() Edit: Do games and demo's calculate the period in realtime before playing samples, or do they just detect whether it's a PAL or NTSC Amiga at startup and use the appropriate lookup table? Regards, Lonewolf10 Last edited by Lonewolf10; 18 June 2011 at 14:06. Reason: Added question |
![]() |
![]() |
#5 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,268
|
I don't know of any games nor music replay routines that adjust periods automatically, there are probably some out there, but the vast majority will just assume PAL. With music replay routines it's complicated further because typically it's all synchronized to the frame rate.
|
![]() |
![]() |
#6 |
AMOS Extensions Developer
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 43
Posts: 1,924
|
When I wrote my demo back in 2011 I only had the one sound sample (dog barking) and just waited a specific length of time before switching off the DMA audio channels. For the game I'm working on right now I plan on having sound effects playing at random intervals in the background, so waiting a fixed length of time would ruin the game and complicate things.
I have written a routine for playing samples of different lengths and frequency's. It works fine, but it keeps playing the sound sample over and over. How do I work out when to turn off the DMA for the audio channel without cutting off the samples halfway through? |
![]() |
![]() |
#7 |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,198
|
You may have a look at phx (I guess he was it) released play-mod-and-samples source. I can`t remember more, but you should find it on eab.
Edit: http://eab.abime.net/showthread.php?t=65430 |
![]() |
![]() |
#8 | |
WinUAE developer
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 48
Posts: 25,945
|
Quote:
Just make sure sample has started playing (Paula has fetched first 16-bit word), you can also wait for audio interrupt, it comes just after playing starts. |
|
![]() |
![]() |
#9 |
AMOS Extensions Developer
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 43
Posts: 1,924
|
Thanks for the help guys
![]() |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need sound samples from Starray! | Dunny | support.Games | 7 | 10 June 2013 19:30 |
Best way to get samples onto the amiga... | ElectroBlaster | Amiga scene | 4 | 21 October 2012 17:13 |
Need Samples from Turrican 2 | hipoonios | request.Other | 9 | 07 April 2010 18:03 |
Sound and Voice Samples - Help... | Peter | support.Other | 1 | 24 March 2007 01:21 |
Project samples/mods? | Dastardly | project.Sprites | 2 | 02 October 2006 11:27 |
|
|