diff music2/koedec_ogg.cc @ 52:15a18fbe6f21

* Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author thib
date Sat, 18 Apr 2009 18:35:39 +0000
parents 53a311ea8289
children 4416cfac86ae
line wrap: on
line diff
--- a/music2/koedec_ogg.cc
+++ b/music2/koedec_ogg.cc
@@ -25,11 +25,11 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include<stdio.h>
-#include<string.h>
-#include<stdlib.h>
-#include"music.h"
-#include"wavfile.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "music.h"
+#include "wavfile.h"
 
 extern int is_koe_ogg(char* head);
 extern char* decode_koe_ogg(AvgKoeInfo info, int* dest_len);
@@ -45,19 +45,19 @@ extern int is_koe_ogg(char* head) {
 #if HAVE_LIBVORBISFILE || HAVE_LIBVORBISIDEC
 
 #if HAVE_LIBVORBISFILE
-#include<vorbis/vorbisfile.h>
+#include <vorbis/vorbisfile.h>
 #else /* HAVE_LIBVORBISIDEC */
-#include<tremor/ivorbiscodec.h>
-#include<tremor/ivorbisfile.h>
+#include <tremor/ivorbiscodec.h>
+#include <tremor/ivorbisfile.h>
 #endif
 
 #define INITSIZE 65536
 
 static int cur_size = 0;
-static char* out = 0;
+static char* out = NULL;
 static void Resize(void) {
 	char* new_out = (char*)realloc(out, cur_size+INITSIZE);
-	if (new_out == 0) {
+	if (new_out == NULL) {
 		new_out = (char*)malloc(cur_size+INITSIZE);
 		memcpy(new_out, out, cur_size);
 		free(out);
@@ -71,6 +71,7 @@ struct OggInfo {
 	int length;
 	int offset;
 };
+
 /* ogg stream 読み込み用の dummy callback */
 static size_t ogg_readfunc(void* ptr, size_t size, size_t nmemb, void* datasource) {
 	OggInfo* info = (OggInfo*)datasource;
@@ -80,35 +81,38 @@ static size_t ogg_readfunc(void* ptr, si
 	}
 	return fread(ptr, size, nmemb, info->stream);
 }
+
 static int ogg_seekfunc(void* datasource, ogg_int64_t new_offset, int whence) {
 	int pt;
 	OggInfo* info = (OggInfo*)datasource;
 	if (whence == SEEK_SET) pt = info->offset + new_offset;
 	else if (whence == SEEK_CUR) pt = ftell(info->stream) + new_offset;
 	else if (whence == SEEK_END) pt = info->offset + info->length + new_offset;
-	int r = fseek(info->stream, pt, 0);
+	int r = fseek(info->stream, pt, SEEK_SET);
 	return r;
 }
+
 static long ogg_tellfunc(void* datasource) {
 	OggInfo* info = (OggInfo*)datasource;
 	int pos = ftell(info->stream);
 	if (pos == -1) return -1;
 	return pos-info->offset;
 }
+
 static int ogg_closefunc(void* datasource) {
 	return 0;
 }
 
 static int fseek_wrap(FILE *f,ogg_int64_t off,int whence){
-  if(f==NULL)return(-1);
-  return fseek(f,off,whence);
+	if (f == NULL) return(-1);
+	return fseek(f, off, whence);
 }
 
 extern char* decode_koe_ogg(AvgKoeInfo info, int* dest_len) {
-	if (info.stream == 0) return 0;
+	if (info.stream == NULL) return NULL;
 	// Voice ファイルを直接指定すると全ストリームを再生してしまうので
 	// 必要な部分だけ切り出して callback 経由で帰す
-	fseek(info.stream, info.offset, 0);
+	fseek(info.stream, info.offset, SEEK_SET);
 
 	ov_callbacks callback;
 	callback.read_func = &ogg_readfunc;
@@ -125,7 +129,7 @@ extern char* decode_koe_ogg(AvgKoeInfo i
 	int r = ov_open_callbacks((void*)&oinfo, &vf, 0, 0, callback);
 	if (r != 0) {
 		fprintf(stderr,"ogg stream err: %d\n",r);
-		return 0;
+		return NULL;
 	}
 	vorbis_info* vinfo = ov_info(&vf, 0);
 	info.rate = vinfo->rate;
@@ -152,10 +156,11 @@ extern char* decode_koe_ogg(AvgKoeInfo i
 	memcpy(out, header, 0x2c);
 	
 	char* ret = out;
-	out = 0;
+	out = NULL;
 
 	return ret;
 }
+
 struct OggFILE_impl {
 	OggVorbis_File vf;
 	ov_callbacks callback;
@@ -178,7 +183,7 @@ OggFILE::OggFILE(FILE* stream, int len) 
 	int r = ov_open_callbacks( (void*)&(pimpl->oinfo), &(pimpl->vf), 0, 0, pimpl->callback);
 	if (r != 0) {
 		delete pimpl;
-		pimpl = 0;
+		pimpl = NULL;
 		return;
 	}
 	vorbis_info* vinfo = ov_info(&(pimpl->vf), 0);
@@ -186,15 +191,17 @@ OggFILE::OggFILE(FILE* stream, int len) 
 	wavinfo.Channels = vinfo->channels;
 	wavinfo.DataBits = 16;
 }
+
 OggFILE::~OggFILE() {
-	if (pimpl) {
+	if (pimpl != NULL) {
 		ov_clear(&(pimpl->vf));
 		fclose(pimpl->oinfo.stream);
 		delete pimpl;
 	}
 }
+
 int OggFILE::Read(char* buf, int blksize, int blklen) {
-	if (pimpl == 0) return -1;
+	if (pimpl == NULL) return -1;
 #if HAVE_LIBVORBISFILE
 	int r = ov_read( &(pimpl->vf), buf, blksize*blklen, 0, 2, 1, NULL);
 #else /* HAVE_LIBVORBISIDEC */
@@ -214,15 +221,18 @@ int OggFILE::Read(char* buf, int blksize
 	}
 	return r / blksize;
 }
+
 void OggFILE::Seek(int count) {
 	ov_pcm_seek(&(pimpl->vf), count);
 	return;
 }
+
 #else
 extern char* decode_koe_ogg(AvgKoeInfo info, int* dest_len) {
-	return 0;
+	return NULL;
 }
-OggFILE::OggFILE(FILE* stream, int a) {pimpl = 0;}
+
+OggFILE::OggFILE(FILE* stream, int a) {pimpl = NULL;}
 OggFILE::~OggFILE(){}
 void OggFILE::Seek(int count){}
 int OggFILE::Read(char* buf, int blksize, int blklen){return -1;}