error : compile audio sample

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
wuda_cn
Posts: 3
Joined: Fri Mar 21, 2008 4:02 pm

error : compile audio sample

Post by wuda_cn »

hi, all:
i compile the following audio sample code, but error appears.

Code: Select all

/*
 * PSP Software Development Kit - http://www.pspdev.org
 * -----------------------------------------------------------------------
 * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
 *
 * main.c - Basic audio sample.
 *
 * Copyright &#40;c&#41; 2005 Frank Buss <[email protected]> &#40;aka Shine&#41;
 *
 * $Id&#58; main.c 1147 2005-10-12 15&#58;52&#58;52Z mrbrown $
 */
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspaudiolib.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

/* Define the module info section */
PSP_MODULE_INFO&#40;"POLYPHONIC", 0, 1, 1&#41;;

/* Define the main thread's attribute value &#40;optional&#41; */
PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER | THREAD_ATTR_VFPU&#41;;

/* Define printf, just to make typing easier */
#define printf	pspDebugScreenPrintf

void dump_threadstatus&#40;void&#41;;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
	sceKernelExitGame&#40;&#41;;

	return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
	int cbid;

	cbid = sceKernelCreateCallback&#40;"Exit Callback", &#40;void *&#41; exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;

	sceKernelSleepThreadCB&#40;&#41;;

	return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

int  pspAudioInit&#40;&#41;;
void pspAudioEndPre&#40;&#41;;
void pspAudioEnd&#40;&#41;;

#define SAMPLE_COUNT 0x10000
float sample&#91;SAMPLE_COUNT&#93;;

#define SAMPLE_RATE 44100

#define OCTAVE_COUNT 6

float octaves&#91;OCTAVE_COUNT&#93;&#91;12&#93;;

typedef struct &#123;
	int note;
	int octave;
	int duration;
&#125; Note_t;

typedef struct &#123;
	Note_t currentNote;
	int noteIndex;
	int currentTime;
	float currentsampleIndex;
	float currentsampleIncrement;
&#125; ChannelState_t;

ChannelState_t channelStates&#91;3&#93;;

// "S" means "#"
#define NOTE_END -2
#define NOTE_PAUSE -1
#define NOTE_C 0
#define NOTE_CS 1
#define NOTE_D 2
#define NOTE_DS 3
#define NOTE_E 4
#define NOTE_F 5
#define NOTE_FS 6
#define NOTE_G 7
#define NOTE_GS 8
#define NOTE_A 9
#define NOTE_AS 10
#define NOTE_B 11

#define EIGHT_NOTE&#40;note, octave, duration&#41; &#123; note, octave, SAMPLE_RATE * duration / 8&#125;

Note_t channel0&#91;&#93; = &#123;
	EIGHT_NOTE&#40;NOTE_D, 4, 7&#41;,
	EIGHT_NOTE&#40;NOTE_E, 4, 1&#41;,
	EIGHT_NOTE&#40;NOTE_F, 4, 1&#41;,
	EIGHT_NOTE&#40;NOTE_E, 4, 1&#41;,
	EIGHT_NOTE&#40;NOTE_F, 4, 1&#41;,
	EIGHT_NOTE&#40;NOTE_E, 4, 1&#41;,
	EIGHT_NOTE&#40;NOTE_A, 3, 9&#41;,
	EIGHT_NOTE&#40;NOTE_B, 3, 2&#41;,
	EIGHT_NOTE&#40;NOTE_C, 4, 1&#41;,
	EIGHT_NOTE&#40;NOTE_D, 4, 7&#41;,
	EIGHT_NOTE&#40;NOTE_E, 4, 1&#41;,
	EIGHT_NOTE&#40;NOTE_F, 4, 1&#41;,
	EIGHT_NOTE&#40;NOTE_E, 4, 1&#41;,
	EIGHT_NOTE&#40;NOTE_F, 4, 1&#41;,
	EIGHT_NOTE&#40;NOTE_E, 4, 1&#41;,
	EIGHT_N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,
	EIGHT_NOTE&#40;NOTE_F, 2, 1&#41;,
	EIGHT_NOTE&#40;NOTE_C, 2, 1&#41;,
	EIGHT_NOTE&#40;NOTE_F, 1, 1&#41;,
	EIGHT_NOTE&#40;NOTE_C, 2, 1&#41;,
	EIGHT_NOTE&#40;NOTE_C, 1, 1&#41;,
	EIGHT_NOTE&#40;NOTE_G, 1, 1&#41;,
	EIGHT_NOTE&#40;NOTE_C, 2, 1&#41;,
	EIGHT_NOTE&#40;NOTE_D, 2, 1&#41;,
	EIGHT_NOTE&#40;NOTE_E, 2, 1&#41;,
	EIGHT_NOTE&#40;NOTE_G, 2, 1&#41;,
	EIGHT_NOTE&#40;NOTE_E, 2, 1&#41;,
	EIGHT_NOTE&#40;NOTE_D, 2, 1&#41;,
	EIGHT_NOTE&#40;NOTE_C, 2, 1&#41;,
	EIGHT_NOTE&#40;NOTE_G, 1, 1&#41;,
	EIGHT_NOTE&#40;NOTE_C, 1, 1&#41;,
	EIGHT_NOTE&#40;NOTE_G, 1, 1&#41;,
	&#123; NOTE_END, 0, 0 &#125;
&#125;;

Note_t* channels&#91;&#93; = &#123; channel0, channel1 &#125;;

void nextNote&#40;int channel&#41;
&#123;
	ChannelState_t* state = &channelStates&#91;channel&#93;;
	state->currentNote = channels&#91;channel&#93;&#91;state->noteIndex&#93;;
	state->currentTime = 0;
	state->currentsampleIndex = 0;
	int note = state->currentNote.note;
	if &#40;note == NOTE_PAUSE&#41; &#123;
		state->currentsampleIncrement = 0;
	&#125; else &#123;
		state->currentsampleIncrement = octaves&#91;state->currentNote.octave&#93;&#91;note&#93; * &#40;&#40;float&#41; SAMPLE_COUNT&#41; / &#40;&#40;float&#41; SAMPLE_RATE&#41;;
	&#125;

	state->noteIndex++;
	if &#40;channels&#91;channel&#93;&#91;state->noteIndex&#93;.note == NOTE_END&#41; state->noteIndex = 0;
&#125;

// calculate current value of attack/delay/sustain/release envelope
float adsr&#40;float time, float duration&#41; &#123;
	if &#40;time < 0.0&#41; return 0.0;
	const float attack = 0.004;
	const float decay = 0.02;
	const float sustain = 0.5;
	const float release = 0.08;
	duration -= attack + decay + release;
	if &#40;time < attack&#41; return time / attack;
	time -= attack;
	if &#40;time < decay&#41; return &#40;decay - time&#41; / decay * &#40;1.0 - sustain&#41; + sustain;
	time -= decay;
	if &#40;time < duration&#41; return sustain;
	time -= duration;
	if &#40;time < release&#41; return &#40;release - time&#41; / release * sustain;
	return 0.0;
&#125;

void audioOutCallback&#40;int channel, unsigned short* buf, unsigned int reqn&#41;
&#123;
	ChannelState_t* state = &channelStates&#91;channel&#93;;
	unsigned int i;
	for &#40;i = 0; i < reqn; i++&#41; &#123;
		float time = &#40;&#40;float&#41; state->currentTime&#41; / &#40;&#40;float&#41; SAMPLE_RATE&#41;;
		if &#40;state->currentTime++ == state->currentNote.duration&#41; nextNote&#40;channel&#41;;
		float value;
		if &#40;state->currentsampleIncrement == 0.0&#41; &#123;
			value = 0.0;
		&#125; else &#123;
			value = sample&#91;&#40;int&#41;state->currentsampleIndex&#93; * adsr&#40;time, &#40;&#40;float&#41; state->currentNote.duration&#41; / &#40;&#40;float&#41; SAMPLE_RATE&#41;&#41;;
			value *= &#40;float&#41; 0x7000;
			state->currentsampleIndex += state->currentsampleIncrement;
			if &#40;state->currentsampleIndex >= SAMPLE_COUNT&#41; state->currentsampleIndex -= &#40;float&#41; SAMPLE_COUNT;
		&#125;
		buf&#91;0&#93; = value;
		buf&#91;1&#93; = value;
		buf += 2;
	&#125;
&#125;

void audioOutCallback0&#40;void *buf, unsigned int reqn, void *userdata&#41; &#123; audioOutCallback&#40;0, buf, reqn&#41;; &#125;
void audioOutCallback1&#40;void *buf, unsigned int reqn, void *userdata&#41; &#123; audioOutCallback&#40;1, buf, reqn&#41;; &#125;

void createPitches&#40;float base, float* target&#41;
&#123;
	int i;
	for &#40;i = 0; i < 12; i++&#41; &#123;
		target&#91;i&#93; = base;
		base *= 1.0594630943592952645618252949463;  // 2^&#40;1/12&#41;
	&#125;
&#125;

int main&#40;void&#41;
&#123;
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;
	printf&#40;"Polyphonic sample by Shine\n\n"&#41;;
	printf&#40;"Soundtrack of the movie\n"&#41;;
	printf&#40;"\"Le fabuleux destin d'Amelie Poulain\"\n"&#41;;
	printf&#40;"by Yann Tiersen\n"&#41;;

        int i;
	int maxAt = SAMPLE_COUNT / 16;
	for &#40;i = 0; i < SAMPLE_COUNT; i++&#41; &#123;
		float value;
		if &#40;i < maxAt&#41; &#123;
			value = &#40;&#40;float&#41; i&#41; / &#40;&#40;float&#41; maxAt&#41; * 2.0 - 1.0;
		&#125; else &#123;
			value = 1.0 - &#40;&#40;float&#41; &#40;i - maxAt&#41;&#41; / &#40;&#40;float&#41; &#40;SAMPLE_COUNT - maxAt&#41;&#41; * 2.0;
		&#125;
		sample&#91;i&#93; = value;
	&#125;
	float base = 40.0;
	for &#40;i = 0; i < OCTAVE_COUNT; i++&#41; &#123;
		createPitches&#40;base, octaves&#91;i&#93;&#41;;
		base *= 2;
	&#125;
	channelStates&#91;0&#93;.noteIndex = 0; nextNote&#40;0&#41;;
	channelStates&#91;1&#93;.noteIndex = 0; nextNote&#40;1&#41;;

	pspAudioInit&#40;&#41;;
	pspAudioSetVolume&#40;0, 0x4000, 0x4000&#41;;
	pspAudioSetVolume&#40;1, 0x4000, 0x4000&#41;;
	pspAudioSetChannelCallback&#40;0, audioOutCallback0, NULL&#41;;
	pspAudioSetChannelCallback&#40;1, audioOutCallback1, NULL&#41;;
	sceKernelSleepThread&#40;&#41;;

	return 0;
&#125;

the compile command :
psp-gcc.exe "C:\devkitPro\devkitPSP\psp\sdk\samples\audio\polyphonic\main.c" -o "C:\devkitPro\devkitPSP\psp\sdk\samples\audio\polyphonic\main.elf" -I"C:\devkitPro\devkitPSP\psp\sdk\include" -I"C:\devkitPro\devkitPSP\psp\include" -I"C:\devkitPro\devkitPSP\psp\include\sys" -I"C:\devkitPro\devkitPSP\psp\sdk\include\libc" -I"C:\devkitPro\devkitPSP\psp\include\arpa" -I"C:\devkitPro\devkitPSP\psp\include\bits" -I"C:\devkitPro\devkitPSP\psp\include\machine" -I"C:\devkitPro\devkitPSP\psp\include\netinet" -L"C:\devkitPro\devkitPSP\lib" -L"C:\devkitPro\devkitPSP\psp\lib" -L"C:\devkitPro\devkitPSP\psp\sdk\lib" -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lpsplibc -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -lpspaudiolib -lpspaudio -lm


the error is :

C:\devkitPro\devkitPSP\psp\sdk\lib\libpspaudiolib.a(pspaudiolib.o): In function `pspAudioEnd':
: undefined reference to `sceKernelDeleteThread'
C:\devkitPro\devkitPSP\psp\sdk\lib\libpspaudiolib.a(pspaudiolib.o): In function `pspAudioInit':
: undefined reference to `sceKernelDeleteThread'


please help me!
thanks in advance!
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

.... is that the whole polyphonic sample included in pspsdk?!?!?!? omg... Seems to be a sdk related issue, like some missing stub...i guess (by your pathnames) you are not using (cygwin+)toolchain+sdk or the heimdall's win32 compiled version... Personally i think issuing compile commands directly without the use of a makefile is NOT a good idea, but i cannot say if that command line is generated by some IDE..Anyway i noticed that the error you report seems to be generated in the compilation of the library itself!! You should compile your sdk before using it...or simply change your sdk to one of the already-made and widely supported on this forum. Good luck.
wuda_cn
Posts: 3
Joined: Fri Mar 21, 2008 4:02 pm

Post by wuda_cn »

thanks very much , jean.

development tool : devKitPro, dev c++.

this is the whole sample inclued in pspsdk of devKitPro tool.
i use dev c++ ide to compile it.
before compile it, i change gcc command, include dir and lib dir of dev c++ compile option to pspsdk related dir. and i update pspsdk to the lastst version from devKitPro website.

now, i want to know where the one of already-made and widely is and which the most popular development tool is.

thanks.
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

Personally i'm using Heimdall's sdk 0.6 for win32 (http://forums.ps2dev.org/viewtopic.php?t=9812) and NetBeans 6.0/Visual c++ express as IDE depending on my mood :)
wuda_cn
Posts: 3
Joined: Fri Mar 21, 2008 4:02 pm

Post by wuda_cn »

thanks very much!
Post Reply