LdB
Posts: 867
Joined: Wed Dec 07, 2016 2:29 pm

Re: Audio output on the Raspberry Pi 3B

Mon Oct 01, 2018 8:05 am

The addresses are created by your LD execution in your makefile compile they will be awkward (requires a bit of work to get to then in C). I suspect the address you are passing in is probably junk.

Instead of dealing with that awkwardness I have converted the whole sound system for you to C and included the sound file in a C macro. That is I removed how you were linking the sound file in from your makefile completely. I am doing it all in C because it is a lot less work.

Here is the conversion of the sound.s file to C which in C is not even 60 lines of code
https://github.com/LdB-ECM/Exchange/blo ... rc/sound.c

The header file has a macro called INCLUDE_BINARY_FILE
https://github.com/LdB-ECM/Exchange/blo ... rc/sound.h

What it does is labels the position ???_start in a section then uses .incbin to include a binary file.
After the file it them places another label ????_end

So the use is
INCLUDE_BINARY_FILE ( var name you want in c, the binary file name including any path, the section name);
So here is my include in main.c

Code: Select all

INCLUDE_BINARY_FILE(Interlude, "src/audio/Interlude.bin", ".rodata.interlude");
Hopefully you get what it does which is to include the binary "interlude.bin" into the code labelling it with a start and end.
So your binary music is jammed into the .rodata section (subsection interlude) as constant data.
As the first variable in the macro is "Interlude" the start and end macro expansion will give

Code: Select all

extern const uint16_t Interlude_start;
extern const uint16_t Interlude_end;
So the address of the start of the music is &Interlude_start and the end is &Interlude_end

LizardLad_1
Posts: 126
Joined: Sat Jan 13, 2018 12:29 am

Re: Audio output on the Raspberry Pi 3B

Mon Oct 01, 2018 9:07 am

Wow, that is quite an elegant solution. I have compared it to my C translation and I see where I went wrong. I never knew it was possible to include a file like that. Thank you so much.

Return to “Bare metal, Assembly language”