Permalink
Browse files

Corrected some stuff & made a sample using audio events

  • Loading branch information...
1 parent feb6a07 commit 431c45761cfbab43275912aaf57ac9e6232f7671 @cebash cebash committed Jan 5, 2011
Showing with 224 additions and 2 deletions.
  1. +1 −1 psl1ght/include/sys/thread.h
  2. +1 −1 psl1ght/sprx/libaudio/exports.h
  3. +77 −0 samples/audio_sync/Makefile
  4. +145 −0 samples/audio_sync/source/main.c
@@ -113,7 +113,7 @@ s32 sys_lwmutex_lock(sys_lwmutex_t *lwmutex, u64 timeout_usec);
s32 sys_lwmutex_trylock(sys_lwmutex_t *lwmutex);
s32 sys_lwmutex_unlock(sys_lwmutex_t *lwmutex);
-typedef u64 sys_event_queue_t;
+typedef u32 sys_event_queue_t;
typedef struct sys_event_t {
u64 source, data_1, data_2, data_3;
} sys_event_t;
@@ -6,7 +6,7 @@ EXPORT(audioPortStart, 0x89be28f2);
EXPORT(audioQuit, 0xca5ac370);
EXPORT(audioPortOpen, 0xcd7bc431);
EXPORT(audioSetPortLevel, 0x56dfe179);
-EXPORT(audioCreateNotifyEventQueue, 0x4e13af04);
+EXPORT(audioCreateNotifyEventQueue, 0x04af134e);
EXPORT(audioMiscSetAccessoryVolume, 0x31211f6b);
EXPORT(audioSetNotifyEventQueue, 0x377e0cd9);
EXPORT(audioGetPortTimestamp, 0x4109d08c);
@@ -0,0 +1,77 @@
+.SUFFIXES:
+ifeq ($(strip $(PSL1GHT)),)
+$(error "PSL1GHT must be set in the environment.")
+endif
+
+include $(PSL1GHT)/Makefile.base
+
+TARGET := $(notdir $(CURDIR))
+BUILD := build
+SOURCE := source
+INCLUDE := include
+DATA := data
+LIBS := -laudio -lm
+
+TITLE := Test Audio - PSL1GHT
+APPID := TESTAUDIO
+CONTENTID := UP0001-$(APPID)_00-0000000000000000
+
+CFLAGS += -g -O2 -Wall --std=gnu99
+CXXFLAGS += -g -O2 -Wall
+
+ifneq ($(BUILD),$(notdir $(CURDIR)))
+
+export OUTPUT := $(CURDIR)/$(TARGET)
+export VPATH := $(foreach dir,$(SOURCE),$(CURDIR)/$(dir)) \
+ $(foreach dir,$(DATA),$(CURDIR)/$(dir))
+export BUILDDIR := $(CURDIR)/$(BUILD)
+export DEPSDIR := $(BUILDDIR)
+
+CFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.c)))
+CXXFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.cpp)))
+SFILES := $(foreach dir,$(SOURCE),$(notdir $(wildcard $(dir)/*.S)))
+BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.bin)))
+
+export OFILES := $(CFILES:.c=.o) \
+ $(CXXFILES:.cpp=.o) \
+ $(SFILES:.S=.o) \
+ $(BINFILES:.bin=.bin.o)
+
+export BINFILES := $(BINFILES:.bin=.bin.h)
+
+export INCLUDES := $(foreach dir,$(INCLUDE),-I$(CURDIR)/$(dir)) \
+ -I$(CURDIR)/$(BUILD)
+
+.PHONY: $(BUILD) clean pkg run
+
+$(BUILD):
+ @[ -d $@ ] || mkdir -p $@
+ @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+clean:
+ @echo Clean...
+ @rm -rf $(BUILD) $(OUTPUT).elf $(OUTPUT).self $(OUTPUT).a $(OUTPUT).pkg
+
+pkg: $(BUILD)
+ @echo Creating PKG...
+ @mkdir -p $(BUILD)/pkg
+ @mkdir -p $(BUILD)/pkg/USRDIR
+ @cp $(ICON0) $(BUILD)/pkg/
+ @$(FSELF) -n $(BUILD)/$(TARGET).elf $(BUILD)/pkg/USRDIR/EBOOT.BIN
+ @$(SFO) --title "$(TITLE)" --appid "$(APPID)" -f $(SFOXML) $(BUILD)/pkg/PARAM.SFO
+ @$(PKG) --contentid $(CONTENTID) $(BUILD)/pkg/ $(OUTPUT).pkg
+
+run: $(BUILD)
+ @$(PS3LOADAPP) $(OUTPUT).self
+
+else
+
+DEPENDS := $(OFILES:.o=.d)
+
+$(OUTPUT).self: $(OUTPUT).elf
+$(OUTPUT).elf: $(OFILES)
+$(OFILES): $(BINFILES)
+
+-include $(DEPENDS)
+
+endif
@@ -0,0 +1,145 @@
+/* VideoInfo:
+ * This example querys the PS3 for its current reslution and prints it to tty.
+ * You will need something that redirects tty to see the output.
+ */
+
+#include <audio/audio.h>
+#include <psl1ght/lv2/timer.h>
+#include <math.h>
+#include <sys/time.h> // gettimeofday, timeval, timersub
+#include <time.h> // ctime
+#include <assert.h>
+#include <stdio.h>
+
+#define SHW64(X) (u32)(((u64)X)>>32), (u32)(((u64)X)&0xFFFFFFFF)
+
+sys_event_queue_t snd_queue; // Queue identifier
+u64 snd_queue_key; // Queue Key
+
+#define PI 3.14159265f
+
+void fillBuffer(float *buf)
+{
+ static float pos=0;
+
+ for (unsigned int i = 0; i < AUDIO_BLOCK_SAMPLES; ++i)
+ {
+ //just fill with a beautiful sine wave :P
+ buf[i*2+0] = sin(pos);
+ //in fact 2 different ones
+ buf[i*2+1] = sin(pos*2);
+ pos+=0.01f;
+ if(pos>M_PI)
+ pos-=2*M_PI;
+ }
+}
+
+u32 playOneBlock(u64 *readIndex, float *audioDataStart)
+{
+ u32 ret = 0;
+ //get position of the hardware
+ u64 current_block = *readIndex;
+
+ u32 audio_block_index = (current_block + 1) % AUDIO_BLOCK_8;
+
+ sys_event_t event;
+ ret = sys_event_queue_receive( snd_queue, &event, 20 * 1000);
+
+ //get position of the block to write
+ float *buf = audioDataStart + 2 /*channelcount*/ * AUDIO_BLOCK_SAMPLES * audio_block_index;
+ printf( "\t\tbuf: 0x%08X.%08X\n", SHW64(buf));
+ fillBuffer(buf);
+
+ return 1;
+}
+
+int main(int argc, const char* argv[])
+{
+ AudioPortParam params;
+ AudioPortConfig config;
+ u32 portNum;
+
+ //initialize the audio system
+ int ret=audioInit();
+
+ printf("audioInit: %d\n",ret);
+
+ //set some parameters we want
+ //either 2 or 8 channel
+ params.numChannels = AUDIO_PORT_2CH;
+ //8 16 or 32 block buffer
+ params.numBlocks = AUDIO_BLOCK_8;
+ //extended attributes
+ params.attr = 0;
+ //sound level (1 is default)
+ params.level = 1;
+
+ //open the port (still stopped)
+ ret=audioPortOpen(&params, &portNum);
+ printf("audioPortOpen: %d\n",ret);
+ printf(" portNum: %d\n",portNum);
+
+ //get the params for the buffers, etc
+ ret=audioGetPortConfig(portNum, &config);
+ printf("audioGetPortConfig: %d\n",ret);
+ printf(" readIndex: 0x%8X\n",config.readIndex);
+ printf(" status: %d\n",config.status);
+ printf(" channelCount: %ld\n",config.channelCount);
+ printf(" numBlocks: %ld\n",config.numBlocks);
+ printf(" portSize: %d\n",config.portSize);
+ printf(" audioDataStart: 0x%8X\n",config.audioDataStart);
+
+ // create an event queue that will tell when a block is read
+ ret=audioCreateNotifyEventQueue( &snd_queue, &snd_queue_key);
+ printf("audioCreateNotifyEventQueue: %d\n",ret);
+ printf(" snd_queue: 0x%08X.%08X\n",SHW64(snd_queue));
+ printf(" snd_queue_key: 0x%08X.%08X\n", SHW64(snd_queue_key));
+
+ // Set it to the sprx
+ ret = audioSetNotifyEventQueue(snd_queue_key);
+ printf("audioSetNotifyEventQueue: %d\n",ret);
+ printf(" snd_queue_key: 0x%08X.%08X\n",SHW64(snd_queue_key));
+
+ // clears the event queue
+ ret = sys_event_queue_drain(snd_queue);
+ printf("sys_event_queue_drain: %d\n",ret);
+
+ //start the loop
+ ret=audioPortStart(portNum);
+ printf("audioPortStart: %d\n",ret);
+
+ // To calculate the time spent playing
+ struct timeval tim;
+ struct timezone dummy;
+
+ gettimeofday( &tim, &dummy);
+ double t1=tim.tv_sec+(tim.tv_usec/1000000.0);
+
+ int i=0;
+ while(i<1000)
+ {
+ ret = playOneBlock((u64*)(u64)config.readIndex,(float*)(u64)config.audioDataStart);
+ printf( "playOneBlock: %d (%d)\n", ret, i);
+ if((ret)!=0)
+ i++;
+
+ }
+ gettimeofday( &tim, &dummy);
+ double t2=tim.tv_sec+(tim.tv_usec/1000000.0);
+
+ printf( "Time spent playing: %.6lf\n", t2-t1);
+
+ //shutdown in reverse order
+ ret=audioPortStop(portNum);
+ printf("audioPortStop: %d\n",ret);
+ ret=audioRemoveNotifyEventQueue(snd_queue_key);
+ printf("audioRemoveNotifyEventQueue: %d\n",ret);
+ ret=audioPortClose(portNum);
+ printf("audioPortClose: %d\n",ret);
+ ret=sys_event_queue_destroy(snd_queue, 0);
+ printf("sys_event_queue_destroy: %d\n",ret);
+ ret=audioQuit();
+ printf("audioQuit: %d\n",ret);
+
+ return 0;
+}

0 comments on commit 431c457

Please sign in to comment.