GP32 Converting Sound File To Raw


FabreNZ

Member
Joined
Dec 21, 2004
Messages
132
Hi, I am adding sound into my project, and I have gotten the sample1.c file playing on my GP32, but now I want to convert my own file to play on the GP32.
Mirko says:

Please convert your gp32 samples to

22050Hz
signed
16Bit
stereo or mono

Do this with sox :
sox sample.wav -s sample.raw

So I downloaded sox and used "sox music.wav -s music.raw", but instead of getting this like in the sample:

unsigned char sample1[] = { 70,255,70,255,77,255,77,255,18,255,18,255,252,254,252,254,250,254,250,254,191,254,191,254,43,255,43,255,202   


etc

I got something like this:

              ýüú÷ñëêëîïíìíðòóôøÿÿþþýüÿ ýïæçìõþøîêëô    ùòëæ   


etc

Obviously, my converted file would not play. What did I do wrong? Are there more arguments I must give sox?
 
I think the output file is good but you need to convert it to a C data array to use it (or load it from your code).
SOX seems to convert WAV file to RAW, then convert (with another program) RAW to C (a lot of bin2c programs are available);

Thor
 
have a try with Mirko's CONVERT tool or something similar like X2H(Win) to convert the raw data to an array.
 
Hi, I am adding sound into my project, and I have gotten the sample1.c file playing on my GP32, but now I want to convert my own file to play on the GP32.
Mirko says:

Please convert your gp32 samples to

22050Hz
signed
16Bit
stereo or mono

Do this with sox :
sox sample.wav -s sample.raw

So I downloaded sox and used "sox music.wav -s music.raw", but instead of getting this like in the sample:

unsigned char sample1[] = { 70,255,70,255,77,255,77,255,18,255,18,255,252,254,252,254,250,254,250,254,191,254,191,254,43,255,43,255,202   


etc

I got something like this:

              ýüú÷ñëêëîïíìíðòóôøÿÿþþýüÿ ýïæçìõþøîêëô    ùòëæ   


etc

Obviously, my converted file would not play. What did I do wrong? Are there more arguments I must give sox?

You converted your wav to raw sample data, you can use my little program:
tool.raw2c/raw2c
to convert the RAW sample data to a *.C file.
 
Last edited by a moderator:
I prefer to use the raw files by themselves.

I make a .S file and it's real simple.

Code:
	.ALIGN 2
	.ARM
	
	.GLOBAL  WSCBmp_horz
	.GLOBAL  WSCBmp_vert
	.GLOBAL  WBTitle
	
WSCBmp_horz:
	.INCBIN "wsc_horz.raw"
	
WSCBmp_vert:
	.INCBIN "wsc_vert.raw"

WBTitle:
	.INCBIN "title.raw"

Nevermind the top code, just add it and things will be fine. the .GLOBAL makes the variables available to the linker for linking with other files.

Well, I'm not so good an explaining, but the code should be pretty apparent at what it's doing.

Then, to use it in your C files, you extern the variable in your header or C file, like so:

Code:
extern unsigned short WBTitle[];
extern unsigned short WSCBmp_horz[];
extern unsigned short WSCBmp_vert[];

Then you can use them just like normal variables. Note that the .S file doesn't explain what type of variable they are, this is done by the extern. I made mine unsigned shorts because they are 16bit image data.

Hope this helps. I think it's a lot cleaner and saves using other tools all the time.
 
So I create a file called eg "music.s", paste in that first piece of code, include the file from my main source, and then add the second piece of code you gave me into my main source? Because it's having errors with it. Here's the test files so far:

pong.c
Code:
#include "gp32.h"
#include "title.c"
#include "music.s"

extern unsigned short bgm[];

unsigned short *framebuffer;

int main()
{
   gp_setCpuspeed (22);
   framebuffer = (u16*) FRAMEBUFFER;
   gp_initFramebuffer ((u16*) framebuffer,16,85);
   gp_drawSprite ((u16*) title,0,0,(u16*) framebuffer,320,240);
   gp_startSoundmixer(0);
   gp_addSample( (u16*) bgm,22050, 1, 0,100800);
   while(1) {}
}

music.s
Code:
.ALIGN 2
.ARM

.GLOBAL  bgm

bgm:
.INCBIN "music.raw"

And here are the errors I get when trying to compile:
Code:
arm-elf-gcc -I../lib.src/include -O2 -s -mtune=arm9tdmi   -c -o pong.o pong.c
In file included from pong.c:3:
music.s:3: error: parse error before '.' token
pong.c: In function `main':
pong.c:16: error: `bgm' undeclared (first use in this function)
pong.c:16: error: (Each undeclared identifier is reported only once
pong.c:16: error: for each function it appears in.)
make: *** [pong.o] Error 1
 
Ah, I see what's happening.

Everything looks good, but make sure to tab out the lines in the .S file that start with a period.

The html formatting isn't showing the original tabbing.

so like .INCBIN, .ARM, etc need a single tab out, or any spacing at all really.

Everything else looks good, but tell me if it works for you.

[EDIT] Oh, I just noticed that you're trying to include it in your C file, but that's not how you do it.

You compile both files seperately and then link them together. To do this, you'll probably be better off using a makefile. If you need help, tell me and I'll post an example.
 
You compile both files seperately and then link them together. To do this, you'll probably be better off using a makefile. If you need help, tell me and I'll post an example.

Yeah, I really need help with the makefile too. I've played around a little with the makefile already to get a custom title for the game, here's the makefile so far:

CC = arm-elf-gcc
LD = arm-elf-gcc
AS = arm-elf-as
AR = arm-elf-ar

PRG = pong
OBJS = pong.o

LIBS = -L../lib -lmirkoSDK -lm
CRT0 = ../lib/crt0.S
LNKSCRIPT = ../lib/lnkscript
INCLUDES = -I../lib.src/include
CFLAGS = $(INCLUDES) -O2 -s -mtune=arm9tdmi

all: $(OBJS)
$(CC) -c -o crt0.o $(CRT0)
$(LD) -nostartfiles -s -Wall -Wl,-Map,Test.map -T $(LNKSCRIPT) crt0.o -o $(PRG).elf $(OBJS) $(LIBS)
arm-elf-objcopy -O binary $(PRG).elf $(PRG).bin
b2fxec -a FabreNZ -t Pong $(PRG).bin $(PRG).fxe

install:
gplink put $(PRG).fxe gpmm

clean:
rm -f *.o *~ Test.map *.bin *.elf
 
Last edited by a moderator:
you have to add your "music.s" in the OBJ line of your makefile and leave the #include statement out instead in the code ....
 
I prefer to use the raw files by themselves.

I make a .S file and it's real simple.

This is just brilliant, spent the last hour making a batch file that automatically converts all images in a specified folder into proper .raw files and then put their corresponding code in a .s for easy use in my project. It's a bit of a hack, but still, saves me heaps and heaps of time!
 
Last edited by a moderator:
I prefer to use the raw files by themselves.

I make a .S file and it's real simple.

This is just brilliant, spent the last hour making a batch file that automatically converts all images in a specified folder into proper .raw files and then put their corresponding code in a .s for easy use in my project. It's a bit of a hack, but still, saves me heaps and heaps of time!

wanna share that batch with us?!
 
Last edited by a moderator:
should I also use __attribute__ ((aligned (16))) with that method? or are there any other parameter in the *.S I could/should use?!
 
Code:
[TAB].ALIGN 2
[TAB].ARM

[TAB].GLOBAL  WSCBmp_horz
[TAB].GLOBAL  WSCBmp_vert
[TAB].GLOBAL  WBTitle

WSCBmp_horz:
[TAB].INCBIN "wsc_horz.raw"

WSCBmp_vert:
[TAB].INCBIN "wsc_vert.raw"

WBTitle:
[TAB].INCBIN "title.raw"
 
wanna share that batch with us?!

I think i'll rewrite it to be a bit more dynamic first, it's a bit of a hack as of yet. The biggest problem i had was the generation of the .s file, especially getting the linebreaks right. Once i write my own app to do that, the batch's in business.
But if you're really curious, just ask me on irc.
 
Last edited by a moderator:
I'm having similar problems with this as I had when trying to add my images as c-arrays. My resources.s file is like this:

Code:
	.ALIGN	2
	.ARM

	.GLOBAL	res_title
	.GLOBAL	res_font

res_title:
	.INCBIN "resources/title.gif"

res_font:
	.INCBIN "resources/arial9.gdf"

What happens is - If the gif is not an even number of bytes, I get a compiler warning like this:

Warning: file truncated "resources/title.gif". loaded 47302 of 47303 bytes

Also, the second resource (the font) never loads properly. Yet they both work fine if loaded directly off smc!

Any ideas? Maybe I need a compiler flag to align the data or something? Also, what does the ".ALIGN 2" do? Align it to 2-byte boundaries?
 
Hi, me again.

I read this: http://www.redhat.com/docs/manuals/enterpr...ler/incbin.html

Snippet: Note that the data is not aligned in any way, so it is the user's responsibility to make sure that proper alignment is provided both before and after the incbin directive.

So I did the following, and it seems to work ok (though it looks like overkill):

Code:
.ALIGN 2
.ARM

.GLOBAL res_title
.GLOBAL res_font

.ALIGN 2
res_title:
.INCBIN "resources/title.gif"
.ALIGN 2
res_font:
.INCBIN "resources/arial9.gdf"
.ALIGN 2

Hope it helps someone else!
 
Back
Top