Shop OBEX P1 Docs P2 Docs Learn Events
File Directive trouble? — Parallax Forums

File Directive trouble?

MrBi11MrBi11 Posts: 117
edited 2012-09-10 10:31 in Propeller 1
I'm having issues with "FILE' directive (I think).

Wiring is:
4 inputs (P18-P21) connected to the pushbuttons of the pro board
1 output (P8) connected the Max 4411 Audio output
(added but not shown in documention is a serial output on P3 for an LCD for debugging)

If the files are loaded 20,19,28 & 43 with the "WTF" bytes everything works
if files are simply 20,19,28,43 without the "WTF" only file 20 will play (the following files error out due to sample rate check)
Also it's not just the sample rate, I also get a byte count that is messed up (if I skip the sample check)

My work around (WTF) isn't acceptable as files need to be loaded randomly without causing issues.

Nay ideas??? Thanx
MrBi11


'My Spin Code for wav player:

Con _clkmode = xtal1+pll16x
_xinfreq = 5_000_000 '80Mhz

pub main

repeat
if ina[18]==0
play(@Wav1)
if ina[19]==0
play(@Wav2)
if ina[20]==0
play(@Wav3)
if ina[21]==0
play(@Wav4)


Pub play(Pointer):x|Sample,n,i
' turn on output
DIRA[8]~~
' set up counters
CTRA := %00110 << 26 + 8 ' Duty/single ended, port 8

'check sample rate
if long[Pointer+24] <> 8000
return false

' Get length of Wave
n := long[Pointer+40]

' move pointer to start of audio data (skip header)
Pointer += 44
'setup the player loop
n--
i:=0
Sample := cnt+10000
'play loop
repeat i from 0 to n
Sample:=cnt += 7500
waitcnt(Sample)
FRQA:=(byte[Pointer+i])<<24

return true

Dat
Wav1 byte
file "ENG-020.wav"
WTF byte 1,1 ' this placeholder fixes the odd file size issue
Wav2 byte
file "ENG-019.wav"
Wav3 byte
file "ENG-028.wav"
Wav4 byte
file "ENG-043.wav"


FILE ENG-019.wav:
8bit 8Khz PCM
file size: 7360 (8192 on disk)

Header of ENG-019.wav:

00000000- 52 49 46 46 B8 1C 00 00 57 41 56 45 66 6D 74 20 [RIFF....WAVEfmt ]
00000001- 10 00 00 00 01 00 01 00 40 1F 00 00 40 1F 00 00 [........@...@...]
00000002- 01 00 08 00 64 61 74 61 93 1C 00 00 80 80 80 80 [....data........]
00000003- 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 [................]


FILE ENG-020.wav:
8bit 8Khz PCM
file size: 5478 (8192 on disk)

Header of ENG-020.wav:

00000000- 52 49 46 46 5E 15 00 00 57 41 56 45 66 6D 74 20 [RIFF^...WAVEfmt ]
00000001- 10 00 00 00 01 00 01 00 40 1F 00 00 40 1F 00 00 [........@...@...]
00000002- 01 00 08 00 64 61 74 61 3A 15 00 00 80 80 80 80 [....data:.......]
00000003- 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 [................]


I think the issue maybe windows reports file 19 as 7360 bytes the wav size in the header is (&H1C93) 7315 but 7315+44=7359
so windows has rounded the file size up causing issues with the 'File' directive of the compiler. I'd think this would cause errors in files following this file, not this one.

I don't understand where this would cause issues in the code (other than consuming an extra byte of memory)
I would think the pointers would still be correct.

I added an LCD display to debug and discovered that the sample rate was &H1F400001 instead of &H1F40 (long[pointer+24])

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-09-10 07:35
    The problem is that you're using BYTE declarations in your DAT section, yet you're assuming that the files are aligned at long boundaries. In your "play" method, you're accessing long[Pointer+24] and long[Pointer+40] yet the Pointer address is not required to be aligned on a long boundary. Try:
    Dat
    Wav1 long
    file "ENG-020.wav"
    Wav2 long
    file "ENG-019.wav"
    Wav3 long 
    file "ENG-028.wav"
    Wav4 long
    file "ENG-043.wav"
    
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-10 07:37
    The lines "if long[Pointer+24] <> 8000" and "n := long[Pointer+40]" assume that the value of Pointer is long-aligned (i.e., it should be a multiple of 4). The Prop ignores the 2 LSBs when accessing a long from memory, so your program is actually using the value starting 1, 2 or 3 bytes before Pointer if it's not long-aligned. You can put a "long" statement between the FILE statements to ensure that each FILE starts on a long boundary.

    EDIT: Mike beat me to it. Do what Mike said.
  • MrBi11MrBi11 Posts: 117
    edited 2012-09-10 07:42
    Thank you, I wish all my girlfriend issues could be fixed just by having a long instead of a byte too.
  • Heater.Heater. Posts: 21,230
    edited 2012-09-10 10:31
    Just get your girl friends to run BASIC. Then you can PEEK and POKE all you like.
Sign In or Register to comment.