Remove Opus example with actual function
Signed-off-by: Mahyar Koshkouei <deltabeard@users.noreply.github.com>
This commit is contained in:
@@ -33,14 +33,17 @@ int playFlac(const char* in)
|
||||
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
|
||||
ndspChnSetInterp(CHANNEL, NDSP_INTERP_POLYPHASE);
|
||||
ndspChnSetRate(CHANNEL, pFlac->sampleRate);
|
||||
ndspChnSetFormat(CHANNEL, pFlac->channels == 2 ? NDSP_FORMAT_STEREO_PCM16 : NDSP_FORMAT_MONO_PCM16);
|
||||
ndspChnSetFormat(CHANNEL, pFlac->channels == 2 ? NDSP_FORMAT_STEREO_PCM16 :
|
||||
NDSP_FORMAT_MONO_PCM16);
|
||||
|
||||
memset(waveBuf, 0, sizeof(waveBuf));
|
||||
waveBuf[0].nsamples = drflac_read_s16(pFlac, SAMPLES_TO_READ, buffer1) / pFlac->channels;
|
||||
waveBuf[0].nsamples =
|
||||
drflac_read_s16(pFlac, SAMPLES_TO_READ, buffer1) / pFlac->channels;
|
||||
waveBuf[0].data_vaddr = &buffer1[0];
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]);
|
||||
|
||||
waveBuf[1].nsamples = drflac_read_s16(pFlac, SAMPLES_TO_READ, buffer2) / pFlac->channels;
|
||||
waveBuf[1].nsamples =
|
||||
drflac_read_s16(pFlac, SAMPLES_TO_READ, buffer2) / pFlac->channels;
|
||||
waveBuf[1].data_vaddr = &buffer2[0];
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[1]);
|
||||
|
||||
@@ -49,12 +52,12 @@ int playFlac(const char* in)
|
||||
* There may be a chance that the music has not started by the time we get
|
||||
* to the while loop. So we ensure that music has started here.
|
||||
*/
|
||||
while(ndspChnIsPlaying(CHANNEL) == false)
|
||||
{}
|
||||
while(ndspChnIsPlaying(CHANNEL) == false);
|
||||
|
||||
while(playing == false || ndspChnIsPlaying(CHANNEL) == true)
|
||||
{
|
||||
u32 kDown;
|
||||
|
||||
/* Number of bytes read from file.
|
||||
* Static only for the purposes of the printf debug at the bottom.
|
||||
*/
|
||||
|
||||
106
source/main.c
106
source/main.c
@@ -27,11 +27,6 @@
|
||||
/* Adds extra debugging text */
|
||||
#define DEBUG 0
|
||||
|
||||
/* From: http://stackoverflow.com/a/1644898 */
|
||||
#define debug_print(fmt, ...) \
|
||||
do { if (DEBUG) fprintf(stderr, "%d:%s(): " fmt, __LINE__,\
|
||||
__func__, __VA_ARGS__); } while (0)
|
||||
|
||||
#define err_print(err) \
|
||||
do { fprintf(stderr, "\nError %d:%s(): %s %s\n", __LINE__, __func__, \
|
||||
err, strerror(errno)); } while (0)
|
||||
@@ -128,9 +123,11 @@ int main(int argc, char **argv)
|
||||
if(closedir(dp) != 0)
|
||||
err_print("Closing directory failed.");
|
||||
|
||||
/* TODO: There is an issue with Unicode files here.
|
||||
/**
|
||||
* TODO: There is an issue with Unicode files here.
|
||||
* Playing a flac file then a file with a name containing the
|
||||
* character 'é' will cause the asprint to not work properly. */
|
||||
* character 'é' will cause the asprint to not work properly.
|
||||
*/
|
||||
if(asprintf(&file, "%s%s", AUDIO_FOLDER, ep->d_name) == -1)
|
||||
{
|
||||
err_print("Constructing file name failed.");
|
||||
@@ -350,8 +347,7 @@ int playWav(const char *wav)
|
||||
* There may be a chance that the music has not started by the time we get
|
||||
* to the while loop. So we ensure that music has started here.
|
||||
*/
|
||||
while(ndspChnIsPlaying(CHANNEL) == false)
|
||||
{}
|
||||
while(ndspChnIsPlaying(CHANNEL) == false);
|
||||
|
||||
while(playing == false || ndspChnIsPlaying(CHANNEL) == true)
|
||||
{
|
||||
@@ -414,9 +410,6 @@ int playWav(const char *wav)
|
||||
DSP_FlushDataCache(buffer2, BUFFER_SIZE);
|
||||
}
|
||||
|
||||
debug_print("Pos: %lx\n", ndspChnGetSamplePos(CHANNEL));
|
||||
debug_print("%s\n", "Before clear");
|
||||
|
||||
ndspChnWaveBufClear(CHANNEL);
|
||||
|
||||
out:
|
||||
@@ -428,92 +421,3 @@ out:
|
||||
linearFree(buffer2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int playOpus(const char* opus)
|
||||
{
|
||||
OggOpusFile *of;
|
||||
int ret;
|
||||
int output_seekable;
|
||||
FILE* outfile;
|
||||
ogg_int64_t pcm_offset;
|
||||
ogg_int64_t pcm_print_offset;
|
||||
ogg_int64_t nsamples;
|
||||
opus_int32 bitrate = 0;
|
||||
int prev_li;
|
||||
|
||||
printf("Size: %u\n", sizeof(of));
|
||||
of = op_open_file(opus, &ret);
|
||||
if(of == NULL)
|
||||
{
|
||||
fprintf(stderr,"Failed to open file '%s': %i\n", opus, ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
outfile = fopen("sdmc:/MUSIC/out.wav", "wb+");
|
||||
if(outfile == NULL){
|
||||
fprintf(stderr,"Failed to open output file : %i\n",ret);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pcm_offset = op_pcm_tell(of);
|
||||
if(pcm_offset != 0){
|
||||
fprintf(stderr, "Non-zero starting PCM offset: %li\n", (long)pcm_offset);
|
||||
}
|
||||
|
||||
printf("pcm_offset: %li\n", pcm_offset);
|
||||
pcm_print_offset = pcm_offset - 48000;
|
||||
|
||||
for(;;){
|
||||
ogg_int64_t next_pcm_offset;
|
||||
opus_int16* pcm = (opus_int16*)malloc(120*48*2*sizeof(opus_int16));
|
||||
unsigned char* out = (unsigned char*)malloc(120*48*2*2*sizeof(unsigned char));
|
||||
int li;
|
||||
int si;
|
||||
static int count = 0;
|
||||
|
||||
ret = op_read_stereo(of, pcm, sizeof(pcm)/sizeof(*pcm));
|
||||
if(ret < 0)
|
||||
{
|
||||
fprintf(stderr, "\nError decoding '%s': %i\n", opus, ret);
|
||||
ret = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
printf("\rCount: %d", count++);
|
||||
|
||||
next_pcm_offset=op_pcm_tell(of);
|
||||
if(pcm_offset+ret!=next_pcm_offset){
|
||||
fprintf(stderr,"\nPCM offset gap! %li+%i!=%li\n",
|
||||
(long)pcm_offset,ret,(long)next_pcm_offset);
|
||||
}
|
||||
pcm_offset=next_pcm_offset;
|
||||
if(ret<=0){
|
||||
ret=EXIT_SUCCESS;
|
||||
break;
|
||||
}
|
||||
/*Ensure the data is little-endian before writing it out.*/
|
||||
for(si=0;si<2*ret;si++){
|
||||
out[2*si+0]=(unsigned char)(pcm[si]&0xFF);
|
||||
out[2*si+1]=(unsigned char)(pcm[si]>>8&0xFF);
|
||||
}
|
||||
if(!fwrite(out,sizeof(*out)*4*ret,1,outfile)){
|
||||
fprintf(stderr,"\nError writing decoded audio data: %s\n",
|
||||
strerror(errno));
|
||||
ret=EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
nsamples+=ret;
|
||||
prev_li=li;
|
||||
|
||||
free(pcm);
|
||||
}
|
||||
|
||||
if(ret==EXIT_SUCCESS){
|
||||
fprintf(stderr,"\nDone: played ");
|
||||
fprintf(stderr," (%li samples @ 48 kHz).\n",(long)nsamples);
|
||||
}
|
||||
fclose(outfile);
|
||||
op_free(of);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
185
source/opus.c
185
source/opus.c
@@ -1,187 +1,6 @@
|
||||
/********************************************************************
|
||||
* *
|
||||
* THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. *
|
||||
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
||||
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||
* *
|
||||
* THE libopusfile SOURCE CODE IS (C) COPYRIGHT 1994-2012 *
|
||||
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
|
||||
* *
|
||||
********************************************************************/
|
||||
#include <3ds.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <opus/opusfile.h>
|
||||
|
||||
// Number of samples per second * channels * size of one sample
|
||||
#define CHANNEL 0x08
|
||||
#define BUFFER_SIZE 120*48*2*sizeof(opus_int16)*32
|
||||
|
||||
int convOpus(const char* in, const char *outf)
|
||||
int playOpus(const char* in)
|
||||
{
|
||||
OggOpusFile *of;
|
||||
FILE *wav;
|
||||
ogg_int64_t duration = 0;
|
||||
int ret;
|
||||
int output_seekable;
|
||||
ogg_int64_t nsamples = 0;
|
||||
opus_int16* pcm = linearAlloc(120*48*2*sizeof(opus_int16)*32);
|
||||
ndspWaveBuf waveBuf;
|
||||
|
||||
of = op_open_file(in, &ret);
|
||||
|
||||
if((wav = fopen(outf, "w+")) == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to open file '%s': %i %s\n",outf,errno, strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(of == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to open file '%s': %i\n",in,ret);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Not really required.
|
||||
output_seekable = fseek(wav, 0, SEEK_CUR);
|
||||
|
||||
if(op_seekable(of))
|
||||
{
|
||||
fprintf(stderr, "\nTotal number of links: %i\n", op_link_count(of));
|
||||
// Get PCM length of entire stream.
|
||||
duration = op_pcm_total(of, -1);
|
||||
fprintf(stderr, "Total duration: ");
|
||||
fprintf(stderr, " (%li samples @ 48 kHz)\n", (long)duration);
|
||||
}
|
||||
else if(output_seekable < 0)
|
||||
fprintf(stderr,"WARNING: Neither input nor output are seekable.\n");
|
||||
|
||||
/* Initialise DSP stuff */
|
||||
if(R_FAILED(ndspInit()))
|
||||
{
|
||||
printf("Initialising ndsp failed.");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
|
||||
ndspChnReset(CHANNEL);
|
||||
ndspChnWaveBufClear(CHANNEL);
|
||||
/* Polyphase sounds much better than linear or no interpolation */
|
||||
ndspChnSetInterp(CHANNEL, NDSP_INTERP_POLYPHASE);
|
||||
ndspChnSetRate(CHANNEL, 48000);
|
||||
ndspChnSetFormat(CHANNEL, NDSP_FORMAT_STEREO_PCM16);
|
||||
memset(&waveBuf, 0, sizeof(waveBuf));
|
||||
waveBuf.data_vaddr = &pcm;
|
||||
|
||||
fprintf(stderr, "PCM %d, %d\n", sizeof(pcm), sizeof(*pcm));
|
||||
|
||||
for(;;)
|
||||
{
|
||||
u32 kDown;
|
||||
static int num = 0;
|
||||
int semsamples = 0;
|
||||
|
||||
hidScanInput();
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
gspWaitForVBlank();
|
||||
|
||||
kDown = hidKeysDown();
|
||||
|
||||
if(kDown & KEY_B)
|
||||
break;
|
||||
|
||||
/* Returns number of samples decoded. */
|
||||
for(int i = 0; i < 32; i++)
|
||||
{
|
||||
ret = op_read_stereo(of, pcm + (120*48*2*i), 120*48*2);
|
||||
nsamples += ret;
|
||||
semsamples += ret;
|
||||
}
|
||||
|
||||
|
||||
if(ret < 0)
|
||||
{
|
||||
fprintf(stderr, "\nError decoding '%s': %i\n", in, ret);
|
||||
ret = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
||||
if(ret == 0)
|
||||
{
|
||||
ret = EXIT_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
if(fwrite(pcm, ret * sizeof(opus_int16) * 2, 1, wav) == 0)
|
||||
{
|
||||
fprintf(stderr, "\nError writing decoded audio data: %s\n",
|
||||
strerror(errno));
|
||||
ret = EXIT_FAILURE;
|
||||
break;
|
||||
}
|
||||
|
||||
waveBuf[0].data_vaddr = &pcm[0];
|
||||
waveBuf[0].nsamples = ret;
|
||||
ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]);
|
||||
while(ndspChnIsPlaying(CHANNEL) == false)
|
||||
{}
|
||||
while(ndspChnIsPlaying(CHANNEL) == true)
|
||||
{}
|
||||
printf(" Buf0: %s.", waveBuf[0].status == NDSP_WBUF_QUEUED ? "Queued" : "Playing");
|
||||
#endif
|
||||
}
|
||||
|
||||
if(ret == EXIT_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "\nDone: played ");
|
||||
fprintf(stderr, " (%li samples @ 48 kHz).\n", (long)nsamples);
|
||||
}
|
||||
|
||||
if(op_seekable(of) && nsamples != duration)
|
||||
{
|
||||
fprintf(stderr, "\nWARNING: Number of output samples does not match "
|
||||
"declared file duration.\n");
|
||||
if(output_seekable < 0)
|
||||
fprintf(stderr, "Output WAV file will be corrupt.\n");
|
||||
}
|
||||
|
||||
if(fclose(wav) != 0)
|
||||
fprintf(stderr, "\nError closing file: %d - %s\n", errno, strerror(errno));
|
||||
|
||||
out:
|
||||
ndspExit();
|
||||
op_free(of);
|
||||
linearFree(pcm);
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
int convOpus(const char* in, const char *out);
|
||||
int playOpus(const char* in);
|
||||
|
||||
Reference in New Issue
Block a user