1 /*---------------------------------------------------------------------------* 2 Project: Revolution THP Audio Library 3 File: thpaudio.h 4 5 Copyright (C)2002-2006 Nintendo All Rights Reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Log: thpaudio.h,v $ 14 Revision 1.2 03/20/2006 11:22:56 hiratsu 15 Fixed unsafe macro. 16 17 Revision 1.1 02/08/2006 02:52:42 aka 18 Imported from Dolphin Tree. 19 20 21 10 03/09/15 9:33a Akagi 22 23 9 03/07/03 10:56a Akagi 24 Renamed some functions. 25 26 8 03/07/01 3:09p Akagi 27 Modified to divide old THPConv.exe into 2 LIBs and 1 EXE by 28 Ohki-san@NTSC. 29 30 7 03/07/01 2:59p Akagi 31 Moved from build/tools/THPConv/include. 32 33 6 03/07/01 9:19a Akagi 34 Moved from securebuild/tools. 35 36 5 02/05/08 2:30p Akagi 37 modified [-trk] option By Tsuji (IRD) 38 39 1 02/01/16 4:56p Akagi 40 Initial revision made by Tsuji-san (IRD). 41 42 $NoKeywords: $ 43 44 *---------------------------------------------------------------------------*/ 45 46 #ifndef __THPAUDIO_H__ 47 #define __THPAUDIO_H__ 48 49 #include <revolution/types.h> 50 #include <revolution/thpfile.h> 51 #include <win32/dsptool.h> 52 53 #ifdef __cplusplus 54 extern "C" { 55 #endif 56 57 #define THP_TAP_SIZE 16 58 59 //#define THP_NTSC_RATE (59.94) 60 #define THP_GC_OUTPUT_RATE (1125.0 / 1124.0) 61 #define THP_OVERLAP_FRAME (50) 62 #define THP_OVERLAP_SAMPLE (14 * THP_OVERLAP_FRAME) 63 #define THP_ENCODE_SAMPLE (3600 * 14) 64 #define THP_SAMPLE_BUFFER_SIZE (THP_ENCODE_SAMPLE + THP_OVERLAP_SAMPLE) 65 #define THP_ADPCM_BUFFER_SIZE ((THP_SAMPLE_BUFFER_SIZE / 14) * 8) 66 67 #define THPADPCMSampleToByte(x) (u32)(((x) / 14) * 8) 68 #define THPGetEncDataPtr(x, y) (u8 *)((u32)(x) + THPADPCMSampleToByte(y)) 69 #define THPGetDecDataPtr(x, y) (s16 *)((u32)(x) + (y) * 2) 70 71 typedef struct 72 { 73 char fileName[_MAX_PATH]; 74 FILE* fileHandle; 75 u32 frequency; 76 u32 channel; 77 u32 bitPerSample; 78 u32 totalSampleSize; 79 u32 dataBlockOffset; 80 u32 curFileOffset; 81 s32 formatType; 82 s32 type; 83 84 } THPAudioFileInfo; 85 86 typedef struct 87 { 88 u32 offsetNextChannel; 89 u32 sampleSize; 90 u16 lCoef[16]; 91 u16 rCoef[16]; 92 u16 lYn1; 93 u16 lYn2; 94 u16 rYn1; 95 u16 rYn2; 96 97 } THPAudioRecordHeader; 98 99 typedef struct 100 { 101 u32 init; 102 u32 cpos; 103 u32 set; 104 u32 readSample; 105 u32 processSample; 106 s16 leftHistory [THP_TAP_SIZE]; 107 s16 rightHistory[THP_TAP_SIZE]; 108 109 } THPAudioResampleParameter; 110 111 typedef struct 112 { 113 THPAudioFileInfo audioInfo; 114 u32 restEncodedSample; 115 u32 currentFrameNumber; 116 f64 frameRate; 117 s16* leftDecodedPtr; 118 s16* rightDecodedPtr; 119 u8* leftADPCMPtr; 120 u8* rightADPCMPtr; 121 ADPCMINFO leftADPCMInfo; 122 ADPCMINFO rightADPCMInfo; 123 THPAudioRecordHeader recordHeader; 124 s16 leftSampleBuffer [THP_SAMPLE_BUFFER_SIZE]; 125 s16 rightSampleBuffer [THP_SAMPLE_BUFFER_SIZE]; 126 s16 leftDecodedBuffer [THP_SAMPLE_BUFFER_SIZE]; 127 s16 rightDecodedBuffer[THP_SAMPLE_BUFFER_SIZE]; 128 u8 leftADPCMBuffer [THP_ADPCM_BUFFER_SIZE]; 129 u8 rightADPCMBuffer [THP_ADPCM_BUFFER_SIZE]; 130 THPAudioResampleParameter resampleParameter; 131 BOOL resampleFlag; 132 133 } THPAudioHandle; 134 135 extern s32 THPAudioInit( void ); 136 extern s32 THPAudioQuit( void ); 137 138 extern THPAudioHandle* THPAudioCreateHandle( char* fileName, f32 framerate ); 139 extern void THPAudioFreeHandle ( THPAudioHandle* handle ); 140 141 extern s32 THPAudioGetInfo ( THPAudioHandle* handle, THPAudioInfo* audioInfo ); 142 extern u32 THPAudioGetTotalSamples ( THPAudioHandle* handle, s32 frame ); 143 extern u32 THPAudioGetFrameSize ( THPAudioHandle* handle, u32 frame ); 144 extern u32 THPAudioGetMaxFrameSize ( THPAudioHandle* handle, s32 frame ); 145 extern u32 THPAudioGetMaxFrameSamples( THPAudioHandle* handle, s32 frame ); 146 147 extern s32 THPAudioWriteFrame( THPAudioHandle* handle, FILE* output, s32 flag ); 148 149 #ifdef __cplusplus 150 } 151 #endif 152 153 #endif //__THPAUDIO_H__ 154