English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General > Coders. Tutorials

 
 
Thread Tools
Old 17 June 2011, 21:42   #1
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 38
Posts: 1,917
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
Am I using the correct formula for calculating the period?

The sample should be played at 11025Hz and is 7673 bytes long.


Regards,
Lonewolf10
Lonewolf10 is offline  
AdSense AdSense  
Old 18 June 2011, 01:00   #2
Leffmann

 
Join Date: Jul 2008
Location: Sweden
Posts: 2,029
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).
Leffmann is offline  
Old 18 June 2011, 01:06   #3
Codetapper
2 contact me: email only!

Codetapper's Avatar
 
Join Date: May 2001
Location: Auckland / New Zealand
Posts: 3,135
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.
Codetapper is offline  
Old 18 June 2011, 03:28   #4
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 38
Posts: 1,917
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 15:06. Reason: Added question
Lonewolf10 is offline  
Old 18 June 2011, 21:16   #5
Leffmann

 
Join Date: Jul 2008
Location: Sweden
Posts: 2,029
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.
Leffmann is offline  
Old 16 February 2013, 23:52   #6
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 38
Posts: 1,917
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?
Lonewolf10 is offline  
Old 17 February 2013, 13:53   #7
daxb
Registered User
 
Join Date: Oct 2009
Location: Germany
Posts: 1,751
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
daxb is offline  
Old 17 February 2013, 14:28   #8
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 42
Posts: 19,953
Quote:
Originally Posted by Lonewolf10 View Post
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?
No need to turn of the DMA. Simply point audio pointer to short empty sample (update both pointer and length) after sample playing has started. Paula will automatically switch to second sample after first sample ends.

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.
Toni Wilen is offline  
Old 18 February 2013, 23:33   #9
Lonewolf10
AMOS Extensions Developer
Lonewolf10's Avatar
 
Join Date: Jun 2007
Location: near Cambridge, UK
Age: 38
Posts: 1,917
Thanks for the help guys
Lonewolf10 is offline  
AdSense AdSense  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need sound samples from Starray! Dunny support.Games 7 10 June 2013 20:30
Best way to get samples onto the amiga... ElectroBlaster Amiga scene 4 21 October 2012 18:13
Need Samples from Turrican 2 hipoonios request.Other 9 07 April 2010 19:03
Sound and Voice Samples - Help... Peter support.Other 1 24 March 2007 02:21
Project samples/mods? Dastardly project.Sprites 2 02 October 2006 12:27

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 16:06.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.14918 seconds with 14 queries