Unfortunately I'm still having issues with looping and finding more issues along the way with PlayMusic()...
I'm attaching the code and the WAV files I'm working woth for examples.
No matter what I get random clicking. It seems to happen about 80% of the time while looping. I've tried various offsets to attempt to overlap the files. It seems that as soon as the file goes silent or PlayMusic() is called I get clicking. I've also found that if a WAV file is less than 1 second then PlayMusic() refuses to play it at all... And for some reason my file, Pew2.wav only partially plays via AGK. It plays fine in WMP and other players.
If someone with more knowledge than me would take a look at this, I'd really appreciate it. I really need sound bite looping to be seamless otherwise I'll have to make sound files that are unnecessarily large.
//-----------------------------------------------------------------------------
// This file and any accompanying data files are free to use.
//
//
// Project Title: WAV Looper
//
// Description: Reads information from a WAV file to get the exact length of
// time the sound is. The sound is then played at that loop interval.
//
//
// Usage notes: Change file name and offset to your liking
//
// Last revision: 2013-01-29
//
//-----------------------------------------------------------------------------
// wav file format structure courtesy of http://www.neurotraces.com/scilab/scilab2/node24.html
// and https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
//
// Field bytes format contains
// 1 0...3 str4 "RIFF" in ASCII
// 2 4...7 int4 Total bytes minus 8
// 3 8...15 str4 "WAVEfmt" Eighth character is a space
// 4 16...19 int4 16 for PCM format
// 5 20...21 int2 1 for PCM format
// 6 22...23 int2 channels
// 7 24...27 int4 sampling frequency
// 8 28...31 int4 bytes per second
// 9 32...33 int2 bytes by capture
// 10 34...35 int2 bits per sample
// 11 36:39 str4 "data"
// 12 40:43 int4 bytes in data
filename$ = "pew.wav"
offset = 0
SetPrintColor(0,255,255)
timer()
//===============================MAIN==========================================
wav_file = OpenToRead(filename$)
for byte = 0 to 3
ReadByte(wav_file)
next byte
file_size_bytes = (ReadInteger(wav_file) + 8)/2 // divide by 2 due to stereo
for byte = 8 to 27
ReadByte(wav_file)
next byte
bytes_per_second = ReadInteger(wav_file)
for byte = 32 to 39
ReadByte(wav_file)
next byte
bytes_in_data = ReadInteger(wav_file)
wav_time# = bytes_in_data*1000.0 / (2*bytes_per_second) // divide by 2 due to stereo
CloseFile(wav_file)
time0 = GetMilliseconds()
LoadMusic(1,filename$)
PlayMusic(1,0)
do
Print("Total file size = " + Str(file_size_bytes) + " bytes")
Print("Bytes per second = " + Str(bytes_per_second))
Print("Bytes in data = " + Str(bytes_in_data))
Print("Wave length = " + Str(wav_time#) + " milliseconds")
Print(Str(wav_time#+offset))
Print(Str(GetMilliseconds() - time0))
if (GetMilliseconds() - time0) > (wav_time#+offset)
PlayMusic(1,0)
time0 = GetMilliseconds()
endif
Sync()
loop
END
//===================================================================================
EDIT: forgot to mention. This is happening in Win7 only, this looper seems fine on Android...