English Amiga Board Playing samples
 Register Amiga FAQ Rules & Help Members List  /  Moderators List Today's Posts Mark Forums Read

 17 June 2011, 20:42 #1 Lonewolf10 AMOS Extensions Developer   Join Date: Jun 2007 Location: near Cambridge, UK Age: 41 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``` Am I using the correct formula for calculating the period? The sample should be played at 11025Hz and is 7673 bytes long. Regards, Lonewolf10
 18 June 2011, 00:00 #2 Leffmann   Join Date: Jul 2008 Location: Sweden Posts: 2,265 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).
 18 June 2011, 00:06 #3 Codetapper 2 contact me: email only!   Join Date: May 2001 Location: Auckland / New Zealand Posts: 3,165 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.
 18 June 2011, 02:28 #4 Lonewolf10 AMOS Extensions Developer   Join Date: Jun 2007 Location: near Cambridge, UK Age: 41 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
 18 June 2011, 20:16 #5 Leffmann   Join Date: Jul 2008 Location: Sweden Posts: 2,265 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.
 16 February 2013, 22:52 #6 Lonewolf10 AMOS Extensions Developer   Join Date: Jun 2007 Location: near Cambridge, UK Age: 41 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?
 17 February 2013, 12:53 #7 daxb Registered User   Join Date: Oct 2009 Location: Germany Posts: 2,788 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
17 February 2013, 13:28   #8
Toni Wilen
WinUAE developer

Join Date: Aug 2001
Location: HĂ¤meenlinna/Finland
Age: 46
Posts: 24,692
Quote:
 Originally Posted by Lonewolf10 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.

 18 February 2013, 22:33 #9 Lonewolf10 AMOS Extensions Developer   Join Date: Jun 2007 Location: near Cambridge, UK Age: 41 Posts: 1,924 Thanks for the help guys

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

 Similar Threads Thread Thread Starter Forum Replies Last Post Dunny support.Games 7 10 June 2013 19:30 ElectroBlaster Amiga scene 4 21 October 2012 17:13 hipoonios request.Other 9 07 April 2010 18:03 Peter support.Other 1 24 March 2007 01:21 Dastardly project.Sprites 2 02 October 2006 11: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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home News Main     Amiga scene     Retrogaming General Discussion     Nostalgia & memories Support     New to Emulation or Amiga scene         Member Introductions     support.WinUAE     support.WinFellow     support.OtherUAE     support.FS-UAE         project.AmigaLive     support.Hardware         Hardware mods         Hardware pics     support.Games     support.Demos     support.Apps     support.Amiga Forever     support.Amix     support.Other Requests     request.UAE Wishlist     request.Old Rare Games     request.Demos     request.Apps     request.Modules     request.Music     request.Other     Looking for a game name ?     Games images which need to be WHDified abime.net - Hall Of Light     HOL news     HOL suggestions and feedback     HOL data problems     HOL contributions abime.net - Amiga Magazine Rack     AMR news     AMR suggestions and feedback     AMR data problems     AMR contributions abime.net - Home Projects     project.Amiga Lore     project.EAB     project.IRC     project.Mods Jukebox     project.Wiki abime.net - Hosted Projects     project.aGTW     project.APoV     project.ClassicWB     project.Jambo!     project.Green Amiga Alien GUIDES     project.Maptapper     project.Sprites     project.WinUAE - Kaillera Other Projects     project.Amiga Demo DVD     project.Amiga Game Factory     project.CARE     project.Amiga File Server     project.CD32 Conversion     project.Game Cover Art         GCA.Feedback and Suggestions         GCA.Work in Progress         GCA.Cover Requests         GCA.Usefull Programs         GCA.Helpdesk     project.KGLoad     project.MAGE     project.Missing Full Shareware Games     project.SPS (was CAPS)     project.TOSEC (amiga only)     project.WHDLoad         project.Killergorilla's WHD packs Misc     Amiga websites reviews     MarketPlace         Swapshop     Kinky Amiga Stuff     Collections     EAB's competition Coders     Coders. General         Coders. Releases         Coders. Tutorials     Coders. Asm / Hardware     Coders. System         Coders. Scripting         Coders. Nextgen     Coders. Language         Coders. C/C++         Coders. AMOS         Coders. Blitz Basic     Coders. Contest         Coders. Entries Creation     Graphics         Graphics. Work In Progress         Graphics. Finished Work         Graphics. Tutorials     Music         Music. Work In Progress         Music. Finished Work         Music. Tutorials

All times are GMT +2. The time now is 04:03.

 -- EAB3 skin ---- EAB2 skin ---- Mobile skin Archive - Top