Minor changes to debug

Added text to show that playback is paused.
Still attempting to add Opus.

Signed-off-by: Mahyar Koshkouei <deltabeard@users.noreply.github.com>
This commit is contained in:
Mahyar Koshkouei
2016-12-21 16:44:13 +00:00
parent 7e33638380
commit 70e920cec6
2 changed files with 52 additions and 32 deletions

View File

@@ -280,6 +280,10 @@ int playWav(const char *wav)
while(playing == false || ndspChnIsPlaying(CHANNEL) == true) while(playing == false || ndspChnIsPlaying(CHANNEL) == true)
{ {
u32 kDown; u32 kDown;
/* Number of bytes read from file.
* Static only for the purposes of the printf debug at the bottom.
*/
static size_t read = 0;
gfxSwapBuffers(); gfxSwapBuffers();
gfxFlushBuffers(); gfxFlushBuffers();
@@ -295,11 +299,14 @@ int playWav(const char *wav)
playing = !playing; playing = !playing;
if(playing == false || lastbuf == true) if(playing == false || lastbuf == true)
{
printf("\33[2K\rPaused");
continue; continue;
}
if(waveBuf[0].status == NDSP_WBUF_DONE) if(waveBuf[0].status == NDSP_WBUF_DONE)
{ {
size_t read = fread(buffer1, 1, BUFFER_SIZE, file); read = fread(buffer1, 1, BUFFER_SIZE, file);
if(read == 0) if(read == 0)
{ {
@@ -314,7 +321,7 @@ int playWav(const char *wav)
if(waveBuf[1].status == NDSP_WBUF_DONE) if(waveBuf[1].status == NDSP_WBUF_DONE)
{ {
size_t read = fread(buffer2, 1, BUFFER_SIZE, file); read = fread(buffer2, 1, BUFFER_SIZE, file);
if(read == 0) if(read == 0)
{ {
@@ -331,8 +338,10 @@ int playWav(const char *wav)
DSP_FlushDataCache(buffer2, BUFFER_SIZE); DSP_FlushDataCache(buffer2, BUFFER_SIZE);
// TODO: Remove this printf. // TODO: Remove this printf.
printf("\rBuf0: %s, Buf1: %s.", waveBuf[0].status == NDSP_WBUF_QUEUED ? "Queued" : "Playing", // \33[2K clears the current line.
waveBuf[1].status == NDSP_WBUF_QUEUED ? "Queued" : "Playing"); printf("\33[2K\rSamp: %lu\tBuf0: %s\tBuf1: %s", read / blockalign,
waveBuf[0].status == NDSP_WBUF_QUEUED ? "Q" : "P",
waveBuf[1].status == NDSP_WBUF_QUEUED ? "Q" : "P");
} }
debug_print("Pos: %lx\n", ndspChnGetSamplePos(CHANNEL)); debug_print("Pos: %lx\n", ndspChnGetSamplePos(CHANNEL));

View File

@@ -9,25 +9,12 @@
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ * * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* * * *
********************************************************************/ ********************************************************************/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/*For fileno()*/
#if !defined(_POSIX_SOURCE)
# define _POSIX_SOURCE 1
#endif
#include <3ds.h> #include <3ds.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <opus/opusfile.h> #include <opus/opusfile.h>
#if defined(_WIN32)
# include "win32utf8.h"
# undef fileno
# define fileno _fileno
#endif
// Number of samples per second * channels * size of one sample // Number of samples per second * channels * size of one sample
#define CHANNEL 0x08 #define CHANNEL 0x08
@@ -41,9 +28,8 @@ int convOpus(const char* in, const char *outf)
int ret; int ret;
int output_seekable; int output_seekable;
ogg_int64_t nsamples = 0; ogg_int64_t nsamples = 0;
opus_int16* pcm = malloc(120*48*2*sizeof(opus_int16)); opus_int16* pcm = linearAlloc(120*48*2*sizeof(opus_int16)*32);
// Buffer to play one second. ndspWaveBuf waveBuf;
ndspWaveBuf waveBuf[2];
of = op_open_file(in, &ret); of = op_open_file(in, &ret);
@@ -59,6 +45,7 @@ int convOpus(const char* in, const char *outf)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// Not really required.
output_seekable = fseek(wav, 0, SEEK_CUR); output_seekable = fseek(wav, 0, SEEK_CUR);
if(op_seekable(of)) if(op_seekable(of))
@@ -86,13 +73,16 @@ int convOpus(const char* in, const char *outf)
ndspChnSetInterp(CHANNEL, NDSP_INTERP_POLYPHASE); ndspChnSetInterp(CHANNEL, NDSP_INTERP_POLYPHASE);
ndspChnSetRate(CHANNEL, 48000); ndspChnSetRate(CHANNEL, 48000);
ndspChnSetFormat(CHANNEL, NDSP_FORMAT_STEREO_PCM16); ndspChnSetFormat(CHANNEL, NDSP_FORMAT_STEREO_PCM16);
memset(waveBuf, 0, sizeof(waveBuf)); memset(&waveBuf, 0, sizeof(waveBuf));
waveBuf.data_vaddr = &pcm;
fprintf(stderr, "PCM %d, %d\n", sizeof(pcm), sizeof(*pcm)); fprintf(stderr, "PCM %d, %d\n", sizeof(pcm), sizeof(*pcm));
for(;;) for(;;)
{ {
u32 kDown; u32 kDown;
static int num = 0;
int semsamples = 0;
hidScanInput(); hidScanInput();
gfxFlushBuffers(); gfxFlushBuffers();
@@ -104,12 +94,14 @@ int convOpus(const char* in, const char *outf)
if(kDown & KEY_B) if(kDown & KEY_B)
break; break;
/* /* Returns number of samples decoded. */
* Although we would generally prefer to use the float interface, WAV for(int i = 0; i < 32; i++)
* files with signed, 16-bit little-endian samples are far more {
* universally supported, so that's what we output. ret = op_read_stereo(of, pcm + (120*48*2*i), 120*48*2);
*/ nsamples += ret;
ret = op_read_stereo(of, pcm, 120*48*2); semsamples += ret;
}
if(ret < 0) if(ret < 0)
{ {
@@ -124,10 +116,31 @@ int convOpus(const char* in, const char *outf)
break; break;
} }
nsamples += ret;
fprintf(stderr, "\rRet: %d, Sample: %li", ret, (long)nsamples); waveBuf.nsamples = semsamples;
fprintf(stderr, "Ret: %d, #: %d, Sample: %li", ret, num++,
(long)semsamples);
DSP_FlushDataCache(pcm, 120*48*2*sizeof(opus_int16)*32);
ndspChnWaveBufAdd(CHANNEL, &waveBuf);
while(waveBuf.status != NDSP_WBUF_DONE)
{
u32 kDown;
hidScanInput();
kDown = hidKeysDown();
if(kDown & KEY_B)
break;
if(kDown & KEY_START)
goto out;
printf("Status: %d:%s\n", waveBuf.status,
waveBuf.status == NDSP_WBUF_QUEUED ? "Que'd" : "Playing");
}
#if 0
// Number of samples read * size of each sample * number of channels // Number of samples read * size of each sample * number of channels
if(fwrite(pcm, ret * sizeof(opus_int16) * 2, 1, wav) == 0) if(fwrite(pcm, ret * sizeof(opus_int16) * 2, 1, wav) == 0)
{ {
@@ -137,7 +150,6 @@ int convOpus(const char* in, const char *outf)
break; break;
} }
#if 0
waveBuf[0].data_vaddr = &pcm[0]; waveBuf[0].data_vaddr = &pcm[0];
waveBuf[0].nsamples = ret; waveBuf[0].nsamples = ret;
ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]); ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]);
@@ -149,8 +161,6 @@ int convOpus(const char* in, const char *outf)
#endif #endif
} }
free(pcm);
if(ret == EXIT_SUCCESS) if(ret == EXIT_SUCCESS)
{ {
fprintf(stderr, "\nDone: played "); fprintf(stderr, "\nDone: played ");
@@ -171,6 +181,7 @@ int convOpus(const char* in, const char *outf)
out: out:
ndspExit(); ndspExit();
op_free(of); op_free(of);
linearFree(pcm);
return ret; return ret;
} }