OSDN Git Service

ソースや.hppファイルも追加 master
authorMyun2 <myun2@nwhite.info>
Thu, 3 May 2012 13:47:05 +0000 (22:47 +0900)
committerMyun2 <myun2@nwhite.info>
Thu, 3 May 2012 13:47:05 +0000 (22:47 +0900)
include/roast/file/riff.hpp [new file with mode: 0644]
include/roast/file/wave.hpp [new file with mode: 0644]
include/roast/file/wavefile.hpp [new file with mode: 0644]
include/roast_riff.h [moved from roast_riff.h with 100% similarity]
include/roast_wave_file.h [moved from roast_wave_file.h with 100% similarity]
include/roast_wave_file_format.h [moved from roast_wave_file_format.h with 100% similarity]
source/roast_riff.c [new file with mode: 0644]
source/roast_wave_file.c [new file with mode: 0644]

diff --git a/include/roast/file/riff.hpp b/include/roast/file/riff.hpp
new file mode 100644 (file)
index 0000000..1190e64
--- /dev/null
@@ -0,0 +1,299 @@
+//     Roast+ License
+
+/*
+       RIFF File Format
+*/
+#ifndef __SFJP_ROAST__file_riff_HPP__
+#define __SFJP_ROAST__file_riff_HPP__
+
+#include "roast/_common.hpp"
+#include "roast_riff.h"
+#include <vector>
+#include <string>
+
+#include "roast/file/file.hpp"
+
+
+_ROAST_NS_START
+
+
+/**** RIFF Class ****************************/
+
+class CRiff
+{
+private:
+       void _Init(){
+               //ZeroMemory( &m_buf, sizeof(m_buf) );
+       }
+protected:
+       //ROAST_PCM_WAVEFILE m_buf;
+       
+       bool Analyze()
+       {
+/*             if ( memcmp( m_pLoadedBuffer, 
+               m_nLoadedBufferSize*/
+               return true;
+       }
+
+public:
+       //      \83R\83\93\83X\83g\83\89\83N\83^
+       CRiff()
+       {
+               _Init();
+
+       };
+
+       //      \83f\83X\83g\83\89\83N\83^
+       virtual ~CRiff(){}
+       
+       ///////////////////////////////////////////////////////
+
+};
+
+
+/*************************************************/
+
+class CRiffChunk
+{
+private:
+protected:
+       ROAST_RIFF_CHUNK_HEADER m_chunk;
+       const CRiffChunk* m_pParentChunk;
+       char m_chunk_name_buf[5];
+
+private:
+       void _Init(){
+               m_pParentChunk = NULL;
+               RoastZeroMemory( &m_chunk, sizeof(m_chunk) );
+               RoastZeroMemory( m_chunk_name_buf, sizeof(m_chunk_name_buf) );
+       }
+
+public:
+       //      \83R\83\93\83X\83g\83\89\83N\83^\81E\83f\83X\83g\83\89\83N\83^
+       CRiffChunk(){ _Init(); }
+       /*CRiffChunk( const CRiffChunk &from ){
+               //m_pParentChunk = &parentChunk;
+               m_chunk = from.m_chunk;
+               m_pParentChunk = from.m_pParentChunk;
+       }*/
+
+       virtual ~CRiffChunk(){}
+
+       ///////////////////////////////////////////////////////////////
+
+       void SetChunkName(const char* szChunkName){ memcpy(m_chunk.chunk_name, szChunkName, 4); }
+       void SetChunkSize(unsigned long nChunkSize){ m_chunk.chunk_size = nChunkSize; }
+       const char* GetChunkName(){
+               //return m_chunk.chunk_name;
+               memcpy( m_chunk_name_buf, m_chunk.chunk_name, sizeof(m_chunk.chunk_size) );
+               return m_chunk_name_buf;
+       }
+       unsigned long GetChunkSize(){ return m_chunk.chunk_size; }
+       ROAST_RIFF_CHUNK_HEADER* GetChunkHeaderStruct(){ return &m_chunk; }
+};
+
+
+
+/////////////////////////////////////////////////
+
+
+class CRiffFileChunk : public CRiffChunk
+{
+protected:
+       //FILE* m_fp;
+       CPosRememFp m_fp;
+
+public:
+       //      \83R\83\93\83X\83g\83\89\83N\83^\81E\83f\83X\83g\83\89\83N\83^
+       CRiffFileChunk(){ m_fp = NULL; }
+       virtual ~CRiffFileChunk(){}
+
+       ///////////////////////////////////////////////////////////////
+
+       bool ReadHeader( FILE* fp )
+       {
+               m_fp = fp;
+               if ( roast_riff_read_chunk_header_fp( fp, &m_chunk ) == NULL )
+                       return false;
+
+               return true;
+       }
+
+       CRiffFileChunk ReadNextChildChunk()
+       {
+
+       }
+};
+
+
+
+///////////////////////////////////////
+
+//     "RIFF" Chunk
+class CRIFF_Chunk : public CRiffFileChunk
+{
+protected:
+       char riff_form_type[5];                         /*  Form Type.  e.g.) "WAVE", "AVI " ...  */
+
+private:
+       void _Init(){
+               RoastZeroMemory( riff_form_type, sizeof(riff_form_type) );
+               memcpy( m_chunk.chunk_name, ROAST_RIFF_FIX_STRING, 4 );
+       }
+
+public:
+       //      \83R\83\93\83X\83g\83\89\83N\83^\81E\83f\83X\83g\83\89\83N\83^
+       CRIFF_Chunk(){ CRIFF_Chunk::_Init(); }
+       CRIFF_Chunk(const char* szFormType){ CRIFF_Chunk::_Init(); SetFormType(szFormType); }
+
+       virtual ~CRIFF_Chunk(){}
+
+       ////////////////////////////////////////////////
+
+       bool ReadRiffHeader( FILE* fp )
+       {
+               /*if ( ReadHeader(fp) != true )
+                       return false;*/
+               m_fp = fp;
+               if ( roast_riff_fseek_RIFF_header( fp ) != ROAST_TRUE )
+                       return false;
+
+               ROAST_RIFF_HEADER riffHeader;
+               if ( roast_riff_read_RIFF_header_fp( fp, &riffHeader ) != ROAST_TRUE )
+                       return false;
+
+               memcpy( &m_chunk, &riffHeader, sizeof(m_chunk) );
+               memcpy( riff_form_type, riffHeader.riff_form_type, sizeof(riffHeader.riff_form_type) );
+
+               return true;
+       }
+
+       ////////////////////////////////////////////////
+
+       void SetFormType(const char* szFormType){ memcpy(riff_form_type, szFormType, 4); }
+       const char* GetFormType(){ return riff_form_type; }
+       char* GetFormTypePtr(){ return riff_form_type; }
+};
+
+
+
+
+
+/************************************************************
+//
+//     RIFF File Class
+//
+*************************************************************/
+
+class CRiffFile : public CRiff, public CFile
+{
+private:
+       typedef CFile _BASE;
+       //typedef CFileBuf _BASE;
+
+       void _Init(){
+               //ZeroMemory( &m_buf, sizeof(m_buf) );
+       }
+
+protected:
+       //ROAST_PCM_WAVEFILE m_buf;
+       
+       bool Analyze()
+       {
+/*             if ( memcmp( m_pLoadedBuffer, 
+               m_nLoadedBufferSize*/
+               return true;
+       }
+
+public:
+       //      \83R\83\93\83X\83g\83\89\83N\83^
+       CRiffFile()
+       {
+               _Init();
+
+       };
+       CRiffFile(const char* szFilePath) : _BASE(szFilePath){ _Init(); };
+       CRiffFile(const std::string &s) : _BASE(s){ _Init(); };
+       CRiffFile(const CFileBuf &file) : _BASE(file){ _Init(); };
+       CRiffFile(const CFile &file) : _BASE(file){ _Init(); };
+       CRiffFile(FILE* fp) { _Init(); SetFp(m_fp); };
+
+       //      \83f\83X\83g\83\89\83N\83^
+       virtual ~CRiffFile(){}
+       
+       ///////////////////////////////////////////////////////
+
+       //      \93Ç\82Ý\8d\9e\82Ý
+       bool Load( const char* szFilePath )
+       {
+               SetFilePath( szFilePath );
+               return Load();
+       }
+       bool Load()
+       {
+               if ( _BASE::Load() == NULL )
+                       return false;
+               
+               return Analyze();
+       }
+
+       /////
+
+       //      \83t\83@\83C\83\8b\82ð\8aJ\82­
+       bool Open( const char* szMode )
+       {
+               //FClose(); -> FOpen() \82Ì\92\86\82Å\83`\83F\83b\83N\82·\82é\82æ\82¤\82É\82µ\82½
+               return ( FOpen(szMode) != NULL ? true : false );
+       }
+
+       bool Open( const char* szFilePath, const char* szMode )
+       {
+               if ( szFilePath != NULL )
+                       SetFilePath( szFilePath );
+               return Open(szMode);
+       }
+
+       bool ReadOpen(){
+               return Open("rb");
+       }
+       bool ReadOpen( const char* szFilePath ){
+               return Open(szFilePath, "rb");
+       }
+
+
+       bool WriteOpen(){
+               return Open("wb");
+       }
+       bool WriteOpen( const char* szFilePath ){
+               return Open(szFilePath, "wb");
+       }
+
+       bool ModifyOpen(){
+               return Open("r+b");
+       }
+       bool ModifyOpen( const char* szFilePath ){
+               return Open(szFilePath, "r+b");
+       }
+
+       ///////////////////////////////////////////////////////
+
+       CRIFF_Chunk ReadRootRiffChunk()
+       {
+               CRIFF_Chunk riffChunk;
+               riffChunk.ReadRiffHeader( m_fp );
+               return riffChunk;
+               /*if ( roast_riff_fseek_RIFF_header( m_fp ) != ROAST_TRUE )
+                       return CRiffChunk();
+
+               if ( roast_riff_fseek_RIFF_header( m_fp ) != ROAST_TRUE )*/
+       }
+};
+
+
+
+
+_ROAST_NS_END
+
+
+
+#endif//__SFJP_ROAST__file_riff_HPP__
diff --git a/include/roast/file/wave.hpp b/include/roast/file/wave.hpp
new file mode 100644 (file)
index 0000000..5834465
--- /dev/null
@@ -0,0 +1 @@
+#include "roast/file/wavefile.hpp"
diff --git a/include/roast/file/wavefile.hpp b/include/roast/file/wavefile.hpp
new file mode 100644 (file)
index 0000000..97eab56
--- /dev/null
@@ -0,0 +1,202 @@
+//     Roast+ License
+
+/*
+       Wave File Format
+*/
+#ifndef __SFJP_ROAST__file_wavefile_HPP__
+#define __SFJP_ROAST__file_wavefile_HPP__
+
+#include "roast/_common.hpp"
+#include "roast_wave_file.h"
+#include <vector>
+#include <string>
+
+#include "roast/file/file.hpp"
+
+
+_ROAST_NS_START
+
+
+class CWaveFile : public CFileBuf
+{
+private:
+       //typedef CFile _BASE;
+       typedef CFileBuf _BASE;
+
+       void _Init(){
+               //ZeroMemory( &m_buf, sizeof(m_buf) );
+       }
+protected:
+       //CFile m_file;
+       //std::string m_fullpath;
+       
+       //ROAST_PCM_WAVEFILE m_buf;
+       
+       bool Analyze()
+       {
+/*             if ( memcmp( m_pLoadedBuffer, 
+               m_nLoadedBufferSize*/
+               return true;
+       }
+       void _SetBit( int nBit ){
+               GetFmtHeader()->usSampleBit = nBit;
+       }
+
+public:
+       //      \83R\83\93\83X\83g\83\89\83N\83^
+       CWaveFile()
+       {
+               _Init();
+
+               ////////////////
+
+               int nLength = 44100*4*2;
+               m_nLoadedBufferSize = sizeof(ROAST_RIFF_HEADER) + sizeof(ROAST_WAVE_FMT_HEADER) + sizeof(ROAST_RIFF_CHUNK_HEADER) + nLength;
+               m_pLoadedBuffer = new unsigned char[m_nLoadedBufferSize];
+
+               //////////////////////////////////////////
+
+               //      RIFF
+               roast_riff_create_chunk( GetRiffHeader(), m_nLoadedBufferSize - 8, ROAST_RIFF_FORM_TYPE_WAVE );
+               /*memcpy( GetRiffHeader()->riff_fix_str, ROAST_RIFF_FIX_STRING, strlen(ROAST_RIFF_FIX_STRING) );
+               GetRiffHeader()->riff_size = m_nLoadedBufferSize - 8;
+               memcpy( GetRiffHeader()->riff_form_type, ROAST_RIFF_FORM_TYPE_WAVE, strlen(ROAST_RIFF_FORM_TYPE_WAVE) );*/
+
+               //      fmt
+               Setup( 44100, 16, true );
+               /*SetSamplingRate( 44100 );
+               SetBit( 16 );
+               SetStereo();*/
+
+               memcpy( GetFmtHeader()->fmt_fix_str, ROAST_WAVEFILE_FMT_FIX_STRING, strlen(ROAST_WAVEFILE_FMT_FIX_STRING) );
+               GetFmtHeader()->fmt_size = 16;
+               GetFmtHeader()->ulBytesPerSec = 44100 * 4;
+               GetFmtHeader()->usBytePerSample = 2 * 2;
+               GetFmtHeader()->usFormatType = ROAST_WAVEFMT_FORMAT_TYPE_PCM;
+
+               //      data
+               memcpy( GetDataHeader()->chunk_name , ROAST_WAVEFILE_DATA_FIX_STRING, strlen(ROAST_WAVEFILE_DATA_FIX_STRING) );
+               GetDataHeader()->chunk_size = nLength;
+       };
+       CWaveFile( int nSamplingRate, char nBit, bool isStereo )
+       {
+
+       }
+       CWaveFile(const char* szFilePath) : _BASE(szFilePath){ _Init(); };
+       CWaveFile(const std::string &s) : _BASE(s){ _Init(); };
+       CWaveFile(const CFileBuf &file) : _BASE(file){ _Init(); };
+       CWaveFile(const CFile &file) : _BASE(file){ _Init(); };
+       CWaveFile(FILE* fp) { _Init(); SetFp(m_fp); };
+
+       //      \83f\83X\83g\83\89\83N\83^
+       virtual ~CWaveFile(){}
+       
+       ///////////////////////////////////////////////////////
+       
+       //      \93Ç\82Ý\8d\9e\82Ý
+       bool Load( const char* szFilePath ){
+               SetFilePath( szFilePath );
+               if ( _BASE::Load() == NULL )
+                       return false;
+               
+               return Analyze();
+       }
+
+       //      \83t\83H\81[\83}\83b\83g\82Ì\90Ý\92è
+       void Setup( unsigned long nSamplingRate, unsigned short nBit, bool isStereo )
+       {
+               SetSamplingRate( nSamplingRate );
+               _SetBit( nBit );
+               if ( isStereo )
+                       SetStereo();
+               else
+                       SetMonoral();
+       }
+
+       bool Create(){}
+
+       bool ReallocInSample( unsigned int nSampleCount )
+       {
+               //      \8dÅ\91å\83T\83\93\83v\83\8b\90\94\82ð\8cv\8eZ
+               unsigned int nLimitSample = 0xffffffff;
+               if ( IsStereo() ){
+                       nLimitSample /= 2;
+                       //nMaxLength++; //      \90Ø\82è\8fã\82°\82É\82·\82é\82½\82ß -> \82¦\81B\82¢\82ç\82È\82¢\82ñ\81E\81E\81E\81H
+               }
+               nLimitSample /= (GetBit()/8);
+               nLimitSample -= ( GetHeaderSize() + GetFooterSize() );
+
+               //      \92´\82¦\82Ä\82È\82¢\81H
+               if ( nSampleCount > nLimitSample )
+                       return false;
+
+               //      \8eÀ\8dÛ\82Ì\83f\81[\83^\83T\83C\83Y\82ð\8cv\8eZ\82·\82é\82¼\82¢
+               unsigned int nDataSize = nSampleCount;
+               if ( IsStereo() ){
+                       nDataSize *= 2;
+               }
+
+               m_nLoadedBufferSize = sizeof(ROAST_RIFF_HEADER) + sizeof(ROAST_WAVE_FMT_HEADER) + sizeof(ROAST_RIFF_CHUNK_HEADER) + nDataSize;
+               m_pLoadedBuffer = new unsigned char[m_nLoadedBufferSize];
+       }
+       bool SetLengthInSample( unsigned int nSampleCount ){ return ReallocInSample(nSampleCount); }
+       bool SetLengthInTimeMs( float fTimeMs ){
+
+       }
+
+       ///////////////////////////////////////////////////////
+       
+       ROAST_RIFF_HEADER* GetRiffHeader(){ return (ROAST_RIFF_HEADER*)m_pLoadedBuffer; }
+       bool RiffHeaderCheck(){
+               if ( memcmp(GetRiffHeader()->riff_fix_str, ROAST_RIFF_FIX_STRING, sizeof(GetRiffHeader()->riff_fix_str) ) != 0 )
+                       return false;
+               else
+                       return true;
+       }
+       ROAST_WAVE_FMT_HEADER* GetFmtHeader(){ return (ROAST_WAVE_FMT_HEADER*)( (unsigned char*)m_pLoadedBuffer + sizeof(ROAST_RIFF_HEADER) ); }
+       ROAST_RIFF_CHUNK_HEADER* GetDataHeader(){ return (ROAST_RIFF_CHUNK_HEADER*)( (unsigned char*)m_pLoadedBuffer + sizeof(ROAST_RIFF_HEADER) + sizeof(ROAST_WAVE_FMT_HEADER) ); }
+       void* GetDataBody(){ return (void*)( (unsigned char*)GetDataHeader() + sizeof(ROAST_RIFF_CHUNK_HEADER)); }
+
+       ///////////////////////////////////////////////////////
+
+       void SetSamplingRate( unsigned long nRate ){ GetFmtHeader()->ulSampleRate = nRate; }
+       unsigned long GetSamplingRate( int nBit ){ return GetFmtHeader()->ulSampleRate; }
+       /*void SetBit( int nBit ){
+               GetFmtHeader()->usSampleBit = nBit;
+
+               //      
+       }*/
+       void ConvertBit( unsigned short nBit ){
+               GetFmtHeader()->usSampleBit = nBit;
+
+               //      
+       }
+       unsigned short GetBit(){ return GetFmtHeader()->usSampleBit; }
+
+       void SetMonoral(){
+               GetFmtHeader()->usChannels = ROAST_WAVEFMT_PCM_CHANNELS_MONO;
+       }
+       void SetMonaural(){
+               GetFmtHeader()->usChannels = ROAST_WAVEFMT_PCM_CHANNELS_MONO;
+       }
+       void SetStereo(){
+               GetFmtHeader()->usChannels = ROAST_WAVEFMT_PCM_CHANNELS_STEREO;
+       }
+       bool IsStereo(){
+               return ( GetFmtHeader()->usChannels == ROAST_WAVEFMT_PCM_CHANNELS_STEREO ) ? true : false;
+       }
+
+       ///////////////////////////////////////////////
+
+       int GetHeaderSize(){ return (roast::uchar)GetDataBody() - (roast::uchar)GetBuffer(); }
+       int GetFooterSize(){ return GetBufferSize() - GetDataHeader()->chunk_size - 8; }
+};
+
+_ROAST_NS_END
+
+
+//     typedefs
+typedef roast::CWaveFile CRoastWaveFile;
+
+
+#endif//__SFJP_ROAST__file_wavefile_HPP__
similarity index 100%
rename from roast_riff.h
rename to include/roast_riff.h
similarity index 100%
rename from roast_wave_file.h
rename to include/roast_wave_file.h
diff --git a/source/roast_riff.c b/source/roast_riff.c
new file mode 100644 (file)
index 0000000..4ce2d78
--- /dev/null
@@ -0,0 +1,263 @@
+/*     Roast+ License
+
+//     ### C compilable ###
+*/
+
+#include "roast_wave_file.h"
+
+#include "roast_file.h"
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+
+__ROAST_EXTERN_C_START
+
+
+/*     Read RIFF Header        */
+ROAST_BOOL roast_riff_fseek_RIFF_header( FILE* fp )
+{
+       if ( fseek( fp, 0, SEEK_SET ) ){
+               ROAST_SET_ERRNO( ROAST_RIFF_ERRNO_RIFF_FSEEK_FAILED );
+               return ROAST_FALSE;
+       }
+       return ROAST_TRUE;
+}
+
+
+/*     Read RIFF Header        */
+ROAST_BOOL roast_riff_read_RIFF_header( const char* filename, ROAST_RIFF_HEADER* p_riff_out )
+{
+       int ret;
+       FILE* fp = fopen(filename, "rb");
+
+       ROAST_ERRNO_RESET();
+       
+       if ( fp == NULL ){
+               ROAST_SET_ERRNO( ROAST_ERRNO_FILEOPENERR );
+               return ROAST_FALSE;
+       }
+       
+       ret = roast_riff_read_RIFF_header_fp( fp, p_riff_out );
+       
+       fclose(fp);
+       return ret;
+}
+
+
+/*     Read RIFF Header (File Pointer Specify) */
+/*
+       * fp : Require! File Pointer Setted SEEK_SET 0.
+*/
+ROAST_BOOL roast_riff_read_RIFF_header_fp( FILE* fp, ROAST_RIFF_HEADER* p_riff_out )
+{
+       ROAST_ERRNO_RESET();
+       /*
+               \90æ\93ª\82ªRIFF\82Å\82È\82¢\82Æ\82Ç\82¤\82µ\82æ\82¤\82à\82È\82¢\82Ì\82Å\81A\82Ü\82\9ffread\82Å\82¢\82¢\82Å\82µ\82å\82¤\81E\81E\81E
+
+       ROAST_RIFF_CHUNK_HEADER dummy_riff_header;
+       dummy_riff_header.chunk_size = 0x7fffffff - 8;
+       
+       return roast_read_riff_chunk_header_fp( fp, &dummy_riff_header, "RIFF", (ROAST_RIFF_CHUNK_HEADER*)p_riff_out );
+       */
+       
+       /*      Read Head 12 byte = RIFF Header */
+       if ( fread( p_riff_out, sizeof(ROAST_RIFF_HEADER), 1, fp ) != 1 ){
+               ROAST_SET_ERRNO( ROAST_RIFF_ERRNO_RIFF_RIFF_HEADER_READ_FAILED );
+               return ROAST_FALSE;
+       }
+       
+       /*      \89½\8cÌ\83R\83\81\83\93\83g\83A\83E\83g\82µ\82Ä\82¢\82½\82Ì\82©\81E\81E\81E\81H\95K\97v\82\82á\82È\82¢\81E\81E\81E\81H      */
+       if ( memcmp( p_riff_out->riff_fix_str, ROAST_RIFF_FIX_STRING, sizeof(p_riff_out->riff_fix_str) ) != 0 ){
+               ROAST_SET_ERRNO( ROAST_RIFF_ERRNO_RIFF_RIFF_HEADER_INVALID );
+               return ROAST_FALSE;
+       }
+       
+       return ROAST_TRUE;
+}
+
+
+/*     Read RIFF Chunk         */
+/*ROAST_BOOL roast_read_riff_chunk( const char* filename, ROAST_RIFF_CHUNK_HEADER* p_parent_chunk,
+       const char* chunk_name, void* p_chunk_out, unsigned int chunk_bufsize )
+{
+       return FALSE;
+}*/
+
+
+/*     Read RIFF Chunk (File Pointer Specify)  */
+/*
+       * fp : Require! File Pointer Setted SEEK_SET 0.
+*/
+ROAST_BOOL roast_riff_read_chunk_fp( FILE* fp, ROAST_RIFF_CHUNK_HEADER* p_parent_chunk,
+       const char* chunk_name, void* p_chunk_out, unsigned int chunk_bufsize )
+{
+       ROAST_ERRNO_RESET();
+
+       /*      Chunk Header buffer size check  */
+       if ( sizeof(ROAST_RIFF_CHUNK_HEADER) > chunk_bufsize ){
+               ROAST_SET_ERRNO( ROAST_ERRNO_BUFFER_NOT_ENOUGH );
+               return ROAST_FALSE;
+       }
+
+       /*      Read Chunk Header       */
+       //if ( roast_riff_read_chunk_header_fp( fp, p_parent_chunk, chunk_name, (ROAST_RIFF_CHUNK_HEADER*)p_chunk_out ) != ROAST_TRUE )
+       if ( roast_riff_find_chunk_header_fp( fp, p_parent_chunk, chunk_name, (ROAST_RIFF_CHUNK_HEADER*)p_chunk_out ) != ROAST_TRUE )
+               return ROAST_FALSE;
+
+       /*      Chunk Body buffer size check    */
+       if ( ( ((ROAST_RIFF_CHUNK_HEADER*)p_chunk_out)->chunk_size + 8 ) > chunk_bufsize ){
+               ROAST_SET_ERRNO( ROAST_ERRNO_BUFFER_NOT_ENOUGH );
+               return ROAST_FALSE;
+       }
+       
+       /*      Read Chunk Body         */
+       if ( roast_riff_read_chunk_body_fp( fp, (ROAST_RIFF_CHUNK_HEADER*)p_chunk_out, ((unsigned char*)p_chunk_out)+ sizeof(ROAST_RIFF_CHUNK_HEADER) ) != ROAST_TRUE )
+               return ROAST_FALSE;
+
+       return ROAST_TRUE;
+}
+
+
+
+
+
+
+/*     RIFF Read Chunk Header (File Pointer Specify)   */
+/*
+       * fp : Require! File Pointer Setted Chunk Header.
+*/
+ROAST_RIFF_CHUNK_HEADER* roast_riff_read_chunk_header_fp( FILE* fp, ROAST_RIFF_CHUNK_HEADER* p_chunk_out )
+{
+       unsigned long pos = 0;
+       ROAST_ERRNO_RESET();
+       
+       if ( fread( p_chunk_out, sizeof(ROAST_RIFF_CHUNK_HEADER), 1, fp ) != 1 ){
+               ROAST_SET_ERRNO( ROAST_RIFF_ERRNO_RIFF_HEADER_READ_FAILED );
+               return ROAST_FALSE;
+       }
+
+       return ROAST_FALSE;
+}
+
+/*     RIFF Next Chunk Header (File Pointer Specify)   */
+/*
+       * fp : Require! File Pointer Setted Chunk Body.
+*/
+ROAST_RIFF_CHUNK_HEADER* roast_riff_next_chunk_fp( FILE* fp, ROAST_RIFF_CHUNK_HEADER* p_parent_chunk, ROAST_RIFF_CHUNK_HEADER* p_chunk_out )
+{
+       unsigned long pos = 0;
+       ROAST_ERRNO_RESET();
+
+       /*  Move to Next Chunk  */
+       if ( fseek( fp, p_parent_chunk->chunk_size, SEEK_CUR ) )
+               return NULL;
+       
+       if ( fread( p_chunk_out, sizeof(ROAST_RIFF_CHUNK_HEADER), 1, fp ) != 1 )
+               return NULL;
+
+       return p_chunk_out;
+}
+
+
+/*     Read RIFF Chunk Header (File Pointer Specify)   */
+/*
+       * fp : Require! File Pointer Setted Chunk Header.
+*/
+ROAST_BOOL roast_riff_find_chunk_header_fp( FILE* fp, ROAST_RIFF_CHUNK_HEADER* p_parent_chunk,
+       const char* chunk_name, ROAST_RIFF_CHUNK_HEADER* p_chunk_header_out )
+{
+       unsigned long pos = 0;
+       ROAST_ERRNO_RESET();
+       
+       for(;;)
+       {
+               if ( pos >= ( p_parent_chunk->chunk_size + 8 ) )
+                       break;
+               
+               if ( fread( p_chunk_header_out, sizeof(ROAST_RIFF_CHUNK_HEADER), 1, fp ) != 1 )
+                       return ROAST_FALSE;
+               
+               if ( memcmp( p_chunk_header_out->chunk_name, chunk_name, sizeof(p_chunk_header_out->chunk_name) ) == 0 )
+                       return ROAST_TRUE;
+               else
+               {
+                       /*  Move to Next Chunk  */
+                       if ( fseek( fp, p_chunk_header_out->chunk_size, SEEK_CUR ) )
+                               return ROAST_FALSE;
+                       
+                       pos += p_chunk_header_out->chunk_size;
+               }
+       }
+
+       return ROAST_FALSE;
+       /*return ROAST_TRUE;*/
+}
+
+/*     Read RIFF Chunk Body (File Pointer Specify)     */
+/*
+       * fp : Require! File Pointer Setted Chunk Body.
+*/
+ROAST_BOOL roast_riff_read_chunk_body_fp( FILE* fp, ROAST_RIFF_CHUNK_HEADER* p_chunk_header, void* p_body_out )
+{
+       ROAST_ERRNO_RESET();
+       if ( fread( p_body_out, 1, p_chunk_header->chunk_size, fp ) != p_chunk_header->chunk_size )
+               return ROAST_FALSE;
+       
+       return ROAST_TRUE;
+}
+
+
+
+
+/* ============================================================== */
+
+void* roast_riff_find_chunk_mem(
+       ROAST_RIFF_CHUNK_HEADER* p_parent_chunk, const char* chunk_name )
+{
+       unsigned char* p = (unsigned char*)p_parent_chunk;
+       ROAST_ERRNO_RESET();
+       
+       for(;;)
+       {
+               if ( (unsigned)(p_parent_chunk - p_parent_chunk) >= ( p_parent_chunk->chunk_size + 8 ) )
+                       break;
+               
+/*             if ( fread( p_chunk_header_out, sizeof(ROAST_RIFF_CHUNK_HEADER), 1, fp ) != 1 )
+                       return ROAST_FALSE;*/
+               
+               if ( memcmp( p, chunk_name, sizeof(p_parent_chunk->chunk_name) ) == 0 )
+                       return p;
+               
+               else
+               {
+                       /*  Move to Next Chunk  */
+                       p += ((ROAST_RIFF_CHUNK_HEADER*)p)->chunk_size;
+               }
+       }
+       
+       return NULL;
+}
+
+
+
+void* roast_riff_get_mem_chunk_body( ROAST_RIFF_CHUNK_HEADER* p_chunk_header )
+{
+       ROAST_ERRNO_RESET();
+       return p_chunk_header + sizeof(ROAST_RIFF_CHUNK_HEADER);
+}
+
+
+
+/*     Create RIFF Chunk       */
+ROAST_RIFF_HEADER* roast_riff_create_chunk( ROAST_RIFF_HEADER* buf, unsigned long riff_size, const char* form_type )
+{
+       ROAST_ERRNO_RESET();
+       /*ROAST_RIFF_HEADER* p = buf;*/
+       memcpy( buf->riff_fix_str, ROAST_RIFF_FIX_STRING, sizeof(buf->riff_fix_str) );
+       buf->riff_size = riff_size;
+       memcpy( buf->riff_form_type, form_type, sizeof(buf->riff_form_type) );
+
+       return buf;
+}
+
+__ROAST_EXTERN_C_END
diff --git a/source/roast_wave_file.c b/source/roast_wave_file.c
new file mode 100644 (file)
index 0000000..bac0812
--- /dev/null
@@ -0,0 +1,114 @@
+/*     Roast+ License
+
+//     ### C compilable ###
+*/
+
+#include "roast_wave_file.h"
+
+#include <stdlib.h>
+
+
+__ROAST_EXTERN_C_START
+
+
+
+/*     Read PCM Wave File (Full)       */
+ROAST_PCM_WAVEFILE* roast_read_pcm_wave_file( const char* filename )
+{
+       return NULL;
+}
+
+
+
+/*     Read PCM Wave File (Partially)  */
+ROAST_BOOL roast_part_read_pcm_wave_file( const char* filename, int part_flags, ROAST_PCM_WAVEFILE *p_buf )
+{
+       int ret;
+       FILE* fp = fopen(filename, "rb");
+       
+       if ( fp == NULL )
+               return ROAST_FALSE;
+       
+       ret = roast_part_read_pcm_wave_file_fp( fp, part_flags, p_buf );
+       
+       fclose(fp);
+       return ret;
+}
+
+/*     Read PCM Wave File (Partially / File Pointer Version)   */
+ROAST_BOOL roast_part_read_pcm_wave_file_fp( FILE* fp, int part_flags, ROAST_PCM_WAVEFILE *p_buf )
+{
+       /*  need ftell() and backup?  */
+       
+       /*      Move to Head  */
+       if ( fseek( fp, 0, SEEK_SET ) )
+               return ROAST_FALSE;
+       
+       /*if ( part_flags & */
+       if ( roast_riff_read_RIFF_header_fp( fp, &p_buf->riff ) != ROAST_TRUE )
+               return ROAST_FALSE;
+       
+       /*  Check "RIFF" Chunk Name  */
+       /*if ( memcmp( p_buf->riff.riff_fix_str, ROAST_RIFF_FIX_STRING, sizeof(p_buf->riff.riff_fix_str) ) != 0 )
+               return ROAST_FALSE;*/
+
+       /*  Check "WAVE" Form Name  */
+       if ( memcmp( p_buf->riff.riff_form_type, ROAST_RIFF_FORM_TYPE_WAVE, sizeof(p_buf->riff.riff_form_type) ) != 0 )
+               return ROAST_FALSE;
+
+       /* ========================================================= */
+       /*if ( part_flags & ROAST_READ_PCM_WAVE_PART_FMT_HEADER &&
+            part_flags & ROAST_READ_PCM_WAVE_PART_FMT_BODY )
+       {
+               if ( roast_read_riff_chunk_fp( fp,
+                               (ROAST_RIFF_CHUNK_HEADER*) &p_buf->riff, ROAST_WAVEFILE_CHUNK_NAME_FMT,
+                               (ROAST_RIFF_CHUNK_HEADER *) & p_buf->fmt, sizeof(p_buf->fmt) ) != ROAST_TRUE )
+                       return ROAST_FALSE;
+       }
+       
+       else*/ if ( part_flags & ROAST_READ_PCM_WAVE_PART_FMT_HEADER )
+       {
+               //if ( roast_read_riff_chunk_header_fp( fp,
+               if ( roast_riff_find_chunk_header_fp( fp,
+                               (ROAST_RIFF_CHUNK_HEADER*) &p_buf->riff, ROAST_WAVEFILE_CHUNK_NAME_FMT,
+                               (ROAST_RIFF_CHUNK_HEADER *) & p_buf->fmt ) != ROAST_TRUE )
+                       return ROAST_FALSE;
+       }
+       
+       if ( part_flags & ROAST_READ_PCM_WAVE_PART_FMT_BODY )
+       {
+               /*if ( roast_read_riff_chunk_body_fp( fp,
+                               (ROAST_RIFF_CHUNK_HEADER*) & p_buf->fmt,
+                               (ROAST_RIFF_CHUNK_HEADER*) ( ((unsigned char*) & p_buf->fmt) + 8) ) != ROAST_TRUE )
+                       return ROAST_FALSE;*/
+               if ( fread( ( ((unsigned char*) & p_buf->fmt) + sizeof(ROAST_RIFF_CHUNK_HEADER) ), 1, sizeof( p_buf->fmt ), fp ) != sizeof( p_buf->fmt ) )
+                       return ROAST_FALSE;
+       }
+
+       return ROAST_TRUE;
+}
+
+
+
+/*     roast_free_pcm_wave_file        */
+void roast_free_pcm_wave_file( ROAST_PCM_WAVEFILE* p_wavefile )
+{
+       free( p_wavefile->p_data );
+       free( p_wavefile );
+}
+
+
+
+
+/* ============================================================== */
+
+
+void* roast_get_wave_fmt_mem( void *p_memfile )
+{
+       
+
+
+       return NULL;
+}
+
+__ROAST_EXTERN_C_END
\ No newline at end of file