s-macke / SAM

Software Automatic Mouth - Tiny Speech Synthesizer
1.21k stars 267 forks source link

Question about filesize #7

Closed CoenraadS closed 6 years ago

CoenraadS commented 6 years ago

Hello

I was wondering about this line in main.c:

unsigned int filesize=bufferlength + 12 + 16 + 8 - 8;

I'm not sure if this is a typo or expected, because the header should be 44 bytes.

Thanks for the project

s-macke commented 6 years ago

I wrote this piece of code around 15 years ago :) According to the German Wikipedia article this field contains the file size-8. https://de.wikipedia.org/wiki/RIFF_WAVE

CoenraadS commented 6 years ago

Ah you are completely correct. I hope you don't mind if I ask one last question.

https://github.com/s-macke/SAM/blob/a2193f95250af50e241cf723a82de5d4e857727d/src/main.c#L256

Everytime the buffer length is used in this project it is divided by 50, but I could not find any reasoning behind this logic.

s-macke commented 6 years ago

Yes, that's weird :) The C64 runs at around 1MHz. So, in theory the output wav file must have a sampling rate of 1000000. However in average the audio signal was only changed every 60 cycles.

The timetable shows the timing behavior. https://github.com/s-macke/SAM/blob/a2193f95250af50e241cf723a82de5d4e857727d/src/render.c#L57

1000000/60=16666 samples per second. For safety I chose then a higher sampling rate of 22050. The value of 50 is then not quite right here. 45 is more appropriate because 1000000/45=22222. However, the output is very close to the original. Hence I never changed the value to the correct value.