diff options
| author | spicyjpeg <thatspicyjpeg@gmail.com> | 2024-01-08 19:15:28 +0100 |
|---|---|---|
| committer | spicyjpeg <thatspicyjpeg@gmail.com> | 2024-01-08 19:15:28 +0100 |
| commit | a149dc9e3b84922a7e52d31e9a56f255a5597dff (patch) | |
| tree | 8f30aacab5d7e0d2569e821c2d3b83c6e703b81e /examples/sound | |
| parent | dd85f9f993427ae69ab905486f8ef372d3960664 (diff) | |
| download | psn00bsdk-a149dc9e3b84922a7e52d31e9a56f255a5597dff.tar.gz | |
Fix examples, update submodules and CI script
Diffstat (limited to 'examples/sound')
| -rw-r--r-- | examples/sound/cdstream/main.c | 11 | ||||
| -rw-r--r-- | examples/sound/cdstream/stream.c | 18 | ||||
| -rw-r--r-- | examples/sound/spustream/main.c | 11 | ||||
| -rw-r--r-- | examples/sound/vagsample/main.c | 31 |
4 files changed, 26 insertions, 45 deletions
diff --git a/examples/sound/cdstream/main.c b/examples/sound/cdstream/main.c index 2bd2142..2a9bbab 100644 --- a/examples/sound/cdstream/main.c +++ b/examples/sound/cdstream/main.c @@ -152,13 +152,6 @@ typedef struct { char name[16]; } VAG_Header; -#define SWAP_ENDIAN(x) ( \ - (((uint32_t) (x) & 0x000000ff) << 24) | \ - (((uint32_t) (x) & 0x0000ff00) << 8) | \ - (((uint32_t) (x) & 0x00ff0000) >> 8) | \ - (((uint32_t) (x) & 0xff000000) >> 24) \ -) - /* Helper functions */ #define DUMMY_BLOCK_ADDR 0x1000 @@ -250,14 +243,14 @@ void setup_stream(const CdlLOC *pos) { int num_channels = vag->channels ? vag->channels : 2; int num_chunks = - (SWAP_ENDIAN(vag->size) + vag->interleave - 1) / vag->interleave; + (__builtin_bswap32(vag->size) + vag->interleave - 1) / vag->interleave; __builtin_memset(&config, 0, sizeof(Stream_Config)); config.spu_address = STREAM_BUFFER_ADDR; config.interleave = vag->interleave; config.buffer_size = RAM_BUFFER_SIZE; - config.sample_rate = SWAP_ENDIAN(vag->sample_rate); + config.sample_rate = __builtin_bswap32(vag->sample_rate); // Use the first N channels of the SPU and pan them left/right in pairs // (this assumes the stream contains one or more stereo tracks). diff --git a/examples/sound/cdstream/stream.c b/examples/sound/cdstream/stream.c index 624b6e1..9dfc9ba 100644 --- a/examples/sound/cdstream/stream.c +++ b/examples/sound/cdstream/stream.c @@ -29,7 +29,7 @@ /* Private utilities */ -static volatile Stream_Context *_active_ctx = (void *) 0; +static volatile Stream_Context *volatile _active_ctx = (void *) 0; static Stream_Time _default_timer_function(void) { return VSync(-1); @@ -42,7 +42,7 @@ static int _get_default_timer_rate(void) { /* Interrupt handlers */ static void _spu_irq_handler(void) { - Stream_Context *ctx = _active_ctx; + volatile Stream_Context *ctx = _active_ctx; // Acknowledge the interrupt to ensure it can be triggered again. The only // way to do this is actually to disable the interrupt entirely; we'll @@ -90,13 +90,13 @@ static void _spu_irq_handler(void) { // both channels' loop addresses to make them "jump" to the new buffers, // rather than actually looping when they encounter the loop flag at the end // of the currently playing buffers. - uint32_t offset = 0; uint32_t address = ctx->config.spu_address + (ctx->db_active ? ctx->chunk_size : 0); int sample_rate = ctx->new_sample_rate; ctx->config.sample_rate = sample_rate; + SpuSetTransferStartAddr(address); SPU_IRQ_ADDR = getSPUAddr(address); for (uint32_t ch = 0, mask = ctx->config.channel_mask; mask; ch++, mask >>= 1) { @@ -104,15 +104,14 @@ static void _spu_irq_handler(void) { continue; SPU_CH_FREQ (ch) = getSPUSampleRate(sample_rate); - SPU_CH_LOOP_ADDR(ch) = getSPUAddr(address + offset); - offset += ctx->config.interleave; + SPU_CH_LOOP_ADDR(ch) = getSPUAddr(address); + address += ctx->config.interleave; // Make sure this channel's data ends with an appropriate loop flag. //ptr[offset - 15] |= 0x03; } // Start uploading the next chunk to the SPU. - SpuSetTransferStartAddr(address); SpuWrite((const uint32_t *) ptr, ctx->chunk_size); } @@ -186,6 +185,9 @@ bool Stream_Start(Stream_Context *ctx, bool resume) { int sample_rate = ctx->new_sample_rate; ctx->config.sample_rate = sample_rate; + // Disable the IRQ as we're going to call spu_irq_handler() manually (due to + // finicky SPU timings). + SPU_CTRL &= ~(1 << 6); SpuSetKey(0, ctx->config.channel_mask); for (uint32_t ch = 0, mask = ctx->config.channel_mask; mask; ch++, mask >>= 1) { @@ -200,14 +202,14 @@ bool Stream_Start(Stream_Context *ctx, bool resume) { address += ctx->config.interleave; } - _spu_irq_handler(); SpuSetKey(1, ctx->config.channel_mask); + _spu_irq_handler(); return true; } bool Stream_Stop(void) { - Stream_Context *ctx = _active_ctx; + volatile Stream_Context *ctx = _active_ctx; if (!ctx) return false; diff --git a/examples/sound/spustream/main.c b/examples/sound/spustream/main.c index 28a0ce5..cf91c26 100644 --- a/examples/sound/spustream/main.c +++ b/examples/sound/spustream/main.c @@ -127,13 +127,6 @@ typedef struct { char name[16]; } VAG_Header; -#define SWAP_ENDIAN(x) ( \ - (((uint32_t) (x) & 0x000000ff) << 24) | \ - (((uint32_t) (x) & 0x0000ff00) << 8) | \ - (((uint32_t) (x) & 0x00ff0000) >> 8) | \ - (((uint32_t) (x) & 0xff000000) >> 24) \ -) - /* Interrupt callbacks */ // The first 4 KB of SPU RAM are reserved for capture buffers and psxspu @@ -220,8 +213,8 @@ void init_stream(const VAG_Header *vag) { stream_ctx.data = &((const uint8_t *) vag)[2048]; stream_ctx.buffer_size = buf_size; - stream_ctx.num_chunks = (SWAP_ENDIAN(vag->size) + buf_size - 1) / buf_size; - stream_ctx.sample_rate = SWAP_ENDIAN(vag->sample_rate); + stream_ctx.num_chunks = (__builtin_bswap32(vag->size) + buf_size - 1) / buf_size; + stream_ctx.sample_rate = __builtin_bswap32(vag->sample_rate); stream_ctx.channels = vag->channels ? vag->channels : 1; stream_ctx.db_active = 1; diff --git a/examples/sound/vagsample/main.c b/examples/sound/vagsample/main.c index 701bfb5..4af92e9 100644 --- a/examples/sound/vagsample/main.c +++ b/examples/sound/vagsample/main.c @@ -99,13 +99,6 @@ typedef struct { char name[16]; } VAG_Header; -#define SWAP_ENDIAN(x) ( \ - (((uint32_t) (x) & 0x000000ff) << 24) | \ - (((uint32_t) (x) & 0x0000ff00) << 8) | \ - (((uint32_t) (x) & 0x00ff0000) >> 8) | \ - (((uint32_t) (x) & 0xff000000) >> 24) \ -) - /* Helper functions */ // The first 4 KB of SPU RAM are reserved for capture buffers and psxspu @@ -119,17 +112,17 @@ static int next_sample_addr = ALLOC_START_ADDR; int upload_sample(const void *data, int size) { // Round the size up to the nearest multiple of 64, as SPU DMA transfers // are done in 64-byte blocks. - int _addr = next_sample_addr; - int _size = (size + 63) & 0xffffffc0; + int addr = next_sample_addr; + size = (size + 63) & ~63; SpuSetTransferMode(SPU_TRANSFER_BY_DMA); - SpuSetTransferStartAddr(_addr); + SpuSetTransferStartAddr(addr); - SpuWrite((const uint32_t *) data, _size); + SpuWrite((const uint32_t *) data, size); SpuIsTransferCompleted(SPU_TRANSFER_WAIT); - next_sample_addr = _addr + _size; - return _addr; + next_sample_addr = addr + size; + return addr; } void play_sample(int addr, int sample_rate) { @@ -168,13 +161,13 @@ int main(int argc, const char* argv[]) { SpuInit(); // Upload the samples to the SPU and parse their headers. - VAG_Header *proyt_vag = (VAG_Header *) proyt; - VAG_Header *tdfx_vag = (VAG_Header *) tdfx; + const VAG_Header *proyt_vag = (const VAG_Header *) proyt; + const VAG_Header *tdfx_vag = (const VAG_Header *) tdfx; - int proyt_addr = upload_sample(&proyt_vag[1], SWAP_ENDIAN(proyt_vag->size)); - int tdfx_addr = upload_sample(&tdfx_vag[1], SWAP_ENDIAN(tdfx_vag->size)); - int proyt_sr = SWAP_ENDIAN(proyt_vag->sample_rate); - int tdfx_sr = SWAP_ENDIAN(tdfx_vag->sample_rate); + int proyt_addr = upload_sample(proyt_vag + 1, __builtin_bswap32(proyt_vag->size)); + int tdfx_addr = upload_sample(tdfx_vag + 1, __builtin_bswap32(tdfx_vag->size)); + int proyt_sr = __builtin_bswap32(proyt_vag->sample_rate); + int tdfx_sr = __builtin_bswap32(tdfx_vag->sample_rate); // Set up controller polling. uint8_t pad_buff[2][34]; |
