d13b03311b6794cac170ea46bc117e7adca6fab0
2 ** Copyright (C) 2001-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation; either version 2.1 of the License, or
7 ** (at your option) any later version.
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ** GNU Lesser General Public License for more details.
14 ** You should have received a copy of the GNU Lesser General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 ** The VOC file format is the most brain damaged format I have yet had to deal
21 ** with. No one programmer could have bee stupid enough to put this together.
22 ** Instead it looks like a series of manic, dyslexic assembly language programmers
23 ** hacked it to fit their needs.
38 /*------------------------------------------------------------------------------
39 * Typedefs for file chunks.
42 #define VOC_MAX_SECTIONS 200
47 VOC_SOUND_CONTINUE
= 2,
59 int offset
; /* Offset of zero => silence. */
63 { unsigned int sections
, section_types
;
64 int samplerate
, channels
, bitwidth
;
65 SND_DATA_BLOCKS blocks
[VOC_MAX_SECTIONS
] ;
68 /*------------------------------------------------------------------------------
69 * Private static functions.
72 static int voc_close (SF_PRIVATE
*psf
) ;
73 static int voc_write_header (SF_PRIVATE
*psf
, int calc_length
) ;
74 static int voc_read_header (SF_PRIVATE
*psf
) ;
76 static const char* voc_encoding2str (int encoding
) ;
80 /* These functions would be required for files with more than one VOC_SOUND_DATA
81 ** segment. Not sure whether to bother implementing this.
84 static int voc_multi_init (SF_PRIVATE
*psf
, VOC_DATA
*pvoc
) ;
86 static int voc_multi_read_uc2s (SF_PRIVATE
*psf
, short *ptr
, int len
) ;
87 static int voc_multi_read_les2s (SF_PRIVATE
*psf
, short *ptr
, int len
) ;
89 static int voc_multi_read_uc2i (SF_PRIVATE
*psf
, int *ptr
, int len
) ;
90 static int voc_multi_read_les2i (SF_PRIVATE
*psf
, int *ptr
, int len
) ;
92 static int voc_multi_read_uc2f (SF_PRIVATE
*psf
, float *ptr
, int len
) ;
93 static int voc_multi_read_les2f (SF_PRIVATE
*psf
, float *ptr
, int len
) ;
95 static int voc_multi_read_uc2d (SF_PRIVATE
*psf
, double *ptr
, int len
) ;
96 static int voc_multi_read_les2d (SF_PRIVATE
*psf
, double *ptr
, int len
) ;
99 /*------------------------------------------------------------------------------
104 voc_open (SF_PRIVATE
*psf
)
105 { int subformat
, error
= 0 ;
108 return SFE_VOC_NO_PIPE
;
110 if (psf
->file
.mode
== SFM_READ
|| (psf
->file
.mode
== SFM_RDWR
&& psf
->filelength
> 0))
111 { if ((error
= voc_read_header (psf
)))
115 subformat
= SF_CODEC (psf
->sf
.format
) ;
117 if (psf
->file
.mode
== SFM_WRITE
|| psf
->file
.mode
== SFM_RDWR
)
118 { if ((SF_CONTAINER (psf
->sf
.format
)) != SF_FORMAT_VOC
)
119 return SFE_BAD_OPEN_FORMAT
;
121 psf
->endian
= SF_ENDIAN_LITTLE
;
123 if ((error
= voc_write_header (psf
, SF_FALSE
)))
126 psf
->write_header
= voc_write_header
;
129 psf
->blockwidth
= psf
->bytewidth
* psf
->sf
.channels
;
131 psf
->container_close
= voc_close
;
134 { case SF_FORMAT_PCM_U8
:
135 case SF_FORMAT_PCM_16
:
136 error
= pcm_init (psf
) ;
139 case SF_FORMAT_ALAW
:
140 error
= alaw_init (psf
) ;
143 case SF_FORMAT_ULAW
:
144 error
= ulaw_init (psf
) ;
147 default : return SFE_UNIMPLEMENTED
;
153 /*------------------------------------------------------------------------------
157 voc_read_header (SF_PRIVATE
*psf
)
160 unsigned char block_type
, rate_byte
;
161 short version
, checksum
, encoding
, dataoffset
;
164 /* Set position to start of file to begin reading header. */
165 offset
= psf_binheader_readf (psf
, "pb", 0, creative
, SIGNED_SIZEOF (creative
)) ;
167 if (creative
[sizeof (creative
) - 1] != 0x1A)
168 return SFE_VOC_NO_CREATIVE
;
170 /* Terminate the string. */
171 creative
[sizeof (creative
) - 1] = 0 ;
173 if (strcmp ("Creative Voice File", creative
))
174 return SFE_VOC_NO_CREATIVE
;
176 psf_log_printf (psf
, "%s\n", creative
) ;
178 offset
+= psf_binheader_readf (psf
, "e222", &dataoffset
, &version
, &checksum
) ;
180 psf
->dataoffset
= dataoffset
;
182 psf_log_printf (psf
, "dataoffset : %d\n"
184 "checksum : 0x%X\n", psf
->dataoffset
, version
, checksum
) ;
186 if (version
!= 0x010A && version
!= 0x0114)
187 return SFE_VOC_BAD_VERSION
;
189 if (! (psf
->codec_data
= malloc (sizeof (VOC_DATA
))))
190 return SFE_MALLOC_FAILED
;
192 pvoc
= (VOC_DATA
*) psf
->codec_data
;
194 memset (pvoc
, 0, sizeof (VOC_DATA
)) ;
196 /* Set the default encoding now. */
197 psf
->sf
.format
= SF_FORMAT_VOC
; /* Major format */
198 encoding
= SF_FORMAT_PCM_U8
; /* Minor format */
199 psf
->endian
= SF_ENDIAN_LITTLE
;
206 offset
+= psf_binheader_readf (psf
, "1", &block_type
) ;
210 offset
+= psf_binheader_readf (psf
, "e3", &size
) ;
212 psf_log_printf (psf
, " ASCII : %d\n", size
) ;
214 if (size
< sizeof (psf
->header
) - 1)
215 { offset
+= psf_binheader_readf (psf
, "b", psf
->header
, size
) ;
216 psf
->header
[size
] = 0 ;
217 psf_log_printf (psf
, " text : %s\n", psf
->header
) ;
221 offset
+= psf_binheader_readf (psf
, "j", size
) ;
225 offset
+= psf_binheader_readf (psf
, "e32", &size
, &count
) ;
226 psf_log_printf (psf
, " Repeat : %d\n", count
) ;
229 case VOC_SOUND_DATA
:
231 case VOC_EXTENDED_II
:
234 default : psf_log_printf (psf
, "*** Weird block marker (%d)\n", block_type
) ;
240 if (block_type
== VOC_SOUND_DATA
)
241 { unsigned char compression
;
244 offset
+= psf_binheader_readf (psf
, "e311", &size
, &rate_byte
, &compression
) ;
246 psf
->sf
.samplerate
= 1000000 / (256 - (rate_byte
& 0xFF)) ;
248 psf_log_printf (psf
, " Sound Data : %d\n sr : %d => %dHz\n comp : %d\n",
249 size
, rate_byte
, psf
->sf
.samplerate
, compression
) ;
251 if (offset
+ size
- 1 > psf
->filelength
)
252 { psf_log_printf (psf
, "Seems to be a truncated file.\n") ;
253 psf_log_printf (psf
, "offset: %d size: %d sum: %d filelength: %D\n", offset
, size
, offset
+ size
, psf
->filelength
) ;
254 return SFE_VOC_BAD_SECTIONS
;
256 else if (psf
->filelength
- offset
- size
> 4)
257 { psf_log_printf (psf
, "Seems to be a multi-segment file (#1).\n") ;
258 psf_log_printf (psf
, "offset: %d size: %d sum: %d filelength: %D\n", offset
, size
, offset
+ size
, psf
->filelength
) ;
259 return SFE_VOC_BAD_SECTIONS
;
262 psf
->dataoffset
= offset
;
263 psf
->dataend
= psf
->filelength
- 1 ;
265 psf
->sf
.channels
= 1 ;
268 psf
->sf
.format
= SF_FORMAT_VOC
| SF_FORMAT_PCM_U8
;
273 if (block_type
== VOC_EXTENDED
)
274 { unsigned char pack
, stereo
, compression
;
275 unsigned short rate_short
;
278 offset
+= psf_binheader_readf (psf
, "e3211", &size
, &rate_short
, &pack
, &stereo
) ;
280 psf_log_printf (psf
, " Extended : %d\n", size
) ;
282 psf_log_printf (psf
, " size : 4\n") ;
284 psf_log_printf (psf
, " size : %d (should be 4)\n", size
) ;
286 psf_log_printf (psf
, " pack : %d\n"
287 " stereo : %s\n", pack
, (stereo
? "yes" : "no")) ;
290 { psf
->sf
.channels
= 2 ;
291 psf
->sf
.samplerate
= 128000000 / (65536 - rate_short
) ;
294 { psf
->sf
.channels
= 1 ;
295 psf
->sf
.samplerate
= 256000000 / (65536 - rate_short
) ;
298 psf_log_printf (psf
, " sr : %d => %dHz\n", (rate_short
& 0xFFFF), psf
->sf
.samplerate
) ;
300 offset
+= psf_binheader_readf (psf
, "1", &block_type
) ;
302 if (block_type
!= VOC_SOUND_DATA
)
303 { psf_log_printf (psf
, "*** Expecting VOC_SOUND_DATA section.\n") ;
304 return SFE_VOC_BAD_FORMAT
;
307 offset
+= psf_binheader_readf (psf
, "e311", &size
, &rate_byte
, &compression
) ;
309 psf_log_printf (psf
, " Sound Data : %d\n"
311 " comp : %d\n", size
, rate_byte
, compression
) ;
314 if (offset
+ size
- 1 > psf
->filelength
)
315 { psf_log_printf (psf
, "Seems to be a truncated file.\n") ;
316 psf_log_printf (psf
, "offset: %d size: %d sum: %d filelength: %D\n", offset
, size
, offset
+ size
, psf
->filelength
) ;
317 return SFE_VOC_BAD_SECTIONS
;
319 else if (offset
+ size
- 1 < psf
->filelength
)
320 { psf_log_printf (psf
, "Seems to be a multi-segment file (#2).\n") ;
321 psf_log_printf (psf
, "offset: %d size: %d sum: %d filelength: %D\n", offset
, size
, offset
+ size
, psf
->filelength
) ;
322 return SFE_VOC_BAD_SECTIONS
;
325 psf
->dataoffset
= offset
;
326 psf
->dataend
= psf
->filelength
- 1 ;
330 psf
->sf
.format
= SF_FORMAT_VOC
| SF_FORMAT_PCM_U8
;
335 if (block_type
== VOC_EXTENDED_II
)
336 { unsigned char bitwidth
, channels
;
337 int size
, fourbytes
;
339 offset
+= psf_binheader_readf (psf
, "e341124", &size
, &psf
->sf
.samplerate
,
340 &bitwidth
, &channels
, &encoding
, &fourbytes
) ;
342 if (size
* 2 == psf
->filelength
- 39)
343 { int temp_size
= psf
->filelength
- 31 ;
345 psf_log_printf (psf
, " Extended II : %d (SoX bug: should be %d)\n", size
, temp_size
) ;
349 psf_log_printf (psf
, " Extended II : %d\n", size
) ;
351 psf_log_printf (psf
, " sample rate : %d\n"
353 " channels : %d\n", psf
->sf
.samplerate
, bitwidth
, channels
) ;
355 if (bitwidth
== 16 && encoding
== 0)
357 psf_log_printf (psf
, " encoding : 0 (SoX bug: should be 4 for 16 bit signed PCM)\n") ;
360 psf_log_printf (psf
, " encoding : %d => %s\n", encoding
, voc_encoding2str (encoding
)) ;
363 psf_log_printf (psf
, " fourbytes : %X\n", fourbytes
) ;
365 psf
->sf
.channels
= channels
;
367 psf
->dataoffset
= offset
;
368 psf
->dataend
= psf
->filelength
- 1 ;
370 if (size
+ 31 == psf
->filelength
+ 1)
371 { /* Hack for reading files produced using
372 ** sf_command (SFC_UPDATE_HEADER_NOW).
374 psf_log_printf (psf
, "Missing zero byte at end of file.\n") ;
375 size
= psf
->filelength
- 30 ;
378 else if (size
+ 31 > psf
->filelength
)
379 { psf_log_printf (psf
, "Seems to be a truncated file.\n") ;
380 size
= psf
->filelength
- 31 ;
382 else if (size
+ 31 < psf
->filelength
)
383 psf_log_printf (psf
, "Seems to be a multi-segment file (#3).\n") ;
387 psf
->sf
.format
= SF_FORMAT_VOC
| SF_FORMAT_PCM_U8
;
392 psf
->sf
.format
= SF_FORMAT_VOC
| SF_FORMAT_PCM_16
;
397 psf
->sf
.format
= SF_FORMAT_VOC
| SF_FORMAT_ALAW
;
402 psf
->sf
.format
= SF_FORMAT_VOC
| SF_FORMAT_ULAW
;
406 default : /* Unknown */
407 return SFE_UNKNOWN_FORMAT
;
414 } /* voc_read_header */
416 /*====================================================================================
420 voc_write_header (SF_PRIVATE
*psf
, int calc_length
)
421 { sf_count_t current
;
422 int rate_const
, subformat
;
424 current
= psf_ftell (psf
) ;
427 { psf
->filelength
= psf_get_filelen (psf
) ;
429 psf
->datalength
= psf
->filelength
- psf
->dataoffset
;
431 psf
->datalength
-= psf
->filelength
- psf
->dataend
;
433 psf
->sf
.frames
= psf
->datalength
/ (psf
->bytewidth
* psf
->sf
.channels
) ;
436 subformat
= SF_CODEC (psf
->sf
.format
) ;
437 /* Reset the current header length to zero. */
438 psf
->header
[0] = 0 ;
440 psf_fseek (psf
, 0, SEEK_SET
) ;
442 /* VOC marker and 0x1A byte. */
443 psf_binheader_writef (psf
, "eb1", "Creative Voice File", make_size_t (19), 0x1A) ;
445 /* Data offset, version and other. */
446 psf_binheader_writef (psf
, "e222", 26, 0x0114, 0x111F) ;
448 /* Use same logic as SOX.
449 ** If the file is mono 8 bit data, use VOC_SOUND_DATA.
450 ** If the file is mono 16 bit data, use VOC_EXTENED.
451 ** Otherwise use VOC_EXTENED_2.
454 if (subformat
== SF_FORMAT_PCM_U8
&& psf
->sf
.channels
== 1)
455 { /* samplerate = 1000000 / (256 - rate_const) ; */
456 rate_const
= 256 - 1000000 / psf
->sf
.samplerate
;
458 /* First type marker, length, rate_const and compression */
459 psf_binheader_writef (psf
, "e1311", VOC_SOUND_DATA
, (int) (psf
->datalength
+ 1), rate_const
, 0) ;
461 else if (subformat
== SF_FORMAT_PCM_U8
&& psf
->sf
.channels
== 2)
462 { /* sample_rate = 128000000 / (65536 - rate_short) ; */
463 rate_const
= 65536 - 128000000 / psf
->sf
.samplerate
;
465 /* First write the VOC_EXTENDED section
466 ** marker, length, rate_const and compression
468 psf_binheader_writef (psf
, "e13211", VOC_EXTENDED
, 4, rate_const
, 0, 1) ;
470 /* samplerate = 1000000 / (256 - rate_const) ; */
471 rate_const
= 256 - 1000000 / psf
->sf
.samplerate
;
473 /* Now write the VOC_SOUND_DATA section
474 ** marker, length, rate_const and compression
476 psf_binheader_writef (psf
, "e1311", VOC_SOUND_DATA
, (int) (psf
->datalength
+ 1), rate_const
, 0) ;
481 if (psf
->sf
.channels
< 1 || psf
->sf
.channels
> 2)
482 return SFE_CHANNEL_COUNT
;
485 { case SF_FORMAT_PCM_U8
:
487 length
= psf
->sf
.frames
* psf
->sf
.channels
* psf
->bytewidth
+ 12 ;
488 /* Marker, length, sample rate, bitwidth, stereo flag, encoding and fourt zero bytes. */
489 psf_binheader_writef (psf
, "e1341124", VOC_EXTENDED_II
, length
, psf
->sf
.samplerate
, 16, psf
->sf
.channels
, 4, 0) ;
492 case SF_FORMAT_PCM_16
:
494 length
= psf
->sf
.frames
* psf
->sf
.channels
* psf
->bytewidth
+ 12 ;
495 /* Marker, length, sample rate, bitwidth, stereo flag, encoding and fourt zero bytes. */
496 psf_binheader_writef (psf
, "e1341124", VOC_EXTENDED_II
, length
, psf
->sf
.samplerate
, 16, psf
->sf
.channels
, 4, 0) ;
499 case SF_FORMAT_ALAW
:
501 length
= psf
->sf
.frames
* psf
->sf
.channels
* psf
->bytewidth
+ 12 ;
502 psf_binheader_writef (psf
, "e1341124", VOC_EXTENDED_II
, length
, psf
->sf
.samplerate
, 8, psf
->sf
.channels
, 6, 0) ;
505 case SF_FORMAT_ULAW
:
507 length
= psf
->sf
.frames
* psf
->sf
.channels
* psf
->bytewidth
+ 12 ;
508 psf_binheader_writef (psf
, "e1341124", VOC_EXTENDED_II
, length
, psf
->sf
.samplerate
, 8, psf
->sf
.channels
, 7, 0) ;
511 default : return SFE_UNIMPLEMENTED
;
515 psf_fwrite (psf
->header
, psf
->headindex
, 1, psf
) ;
520 psf
->dataoffset
= psf
->headindex
;
523 psf_fseek (psf
, current
, SEEK_SET
) ;
526 } /* voc_write_header */
529 voc_close (SF_PRIVATE
*psf
)
531 if (psf
->file
.mode
== SFM_WRITE
|| psf
->file
.mode
== SFM_RDWR
)
532 { /* Now we know for certain the length of the file we can re-write
533 ** correct values for the FORM, 8SVX and BODY chunks.
535 unsigned char byte
= VOC_TERMINATOR
;
538 psf_fseek (psf
, 0, SEEK_END
) ;
540 /* Write terminator */
541 psf_fwrite (&byte
, 1, 1, psf
) ;
543 voc_write_header (psf
, SF_TRUE
) ;
550 voc_encoding2str (int encoding
)
553 { case 0 : return "8 bit unsigned PCM" ;
554 case 4 : return "16 bit signed PCM" ;
555 case 6 : return "A-law" ;
556 case 7 : return "u-law" ;
559 return "*** Unknown ***" ;
560 } /* voc_encoding2str */
562 /*====================================================================================
567 voc_multi_init (SF_PRIVATE
*psf
, VOC_DATA
*pvoc
)
571 if (pvoc
->bitwidth
== 8)
572 { psf
->read_short
= voc_multi_read_uc2s
;
573 psf
->read_int
= voc_multi_read_uc2i
;
574 psf
->read_float
= voc_multi_read_uc2f
;
575 psf
->read_double
= voc_multi_read_uc2d
;
579 if (pvoc
->bitwidth
== 16)
580 { psf
->read_short
= voc_multi_read_les2s
;
581 psf
->read_int
= voc_multi_read_les2i
;
582 psf
->read_float
= voc_multi_read_les2f
;
583 psf
->read_double
= voc_multi_read_les2d
;
587 psf_log_printf (psf
, "Error : bitwith != 8 && bitwidth != 16.\n") ;
589 return SFE_UNIMPLEMENTED
;
590 } /* voc_multi_read_int */
592 /*------------------------------------------------------------------------------------
596 voc_multi_read_uc2s (SF_PRIVATE
*psf
, short *ptr
, int len
)
600 } /* voc_multi_read_uc2s */
603 voc_multi_read_les2s (SF_PRIVATE
*psf
, short *ptr
, int len
)
607 } /* voc_multi_read_les2s */
611 voc_multi_read_uc2i (SF_PRIVATE
*psf
, int *ptr
, int len
)
615 } /* voc_multi_read_uc2i */
618 voc_multi_read_les2i (SF_PRIVATE
*psf
, int *ptr
, int len
)
622 } /* voc_multi_read_les2i */
626 voc_multi_read_uc2f (SF_PRIVATE
*psf
, float *ptr
, int len
)
630 } /* voc_multi_read_uc2f */
633 voc_multi_read_les2f (SF_PRIVATE
*psf
, float *ptr
, int len
)
637 } /* voc_multi_read_les2f */
641 voc_multi_read_uc2d (SF_PRIVATE
*psf
, double *ptr
, int len
)
645 } /* voc_multi_read_uc2d */
648 voc_multi_read_les2d (SF_PRIVATE
*psf
, double *ptr
, int len
)
652 } /* voc_multi_read_les2d */
656 /*------------------------------------------------------------------------------------
658 Creative Voice (VOC) file format
659 --------------------------------
661 ~From: galt@dsd.es.com
663 (byte numbers are hex!)
666 Series of DATA BLOCKS (bytes 1A+) [Must end w/ Terminator Block]
668 - ---------------------------------------------------------------
673 ------ ------------------------------------------
674 00-12 "Creative Voice File"
675 13 1A (eof to abort printing of file)
676 14-15 Offset of first datablock in .voc file (std 1A 00
678 16-17 Version number (minor,major) (VOC-HDR puts 0A 01)
679 18-19 1's Comp of Ver. # + 1234h (VOC-HDR puts 29 11)
681 - ---------------------------------------------------------------
686 Data Block: TYPE(1-byte), SIZE(3-bytes), INFO(0+ bytes)
687 NOTE: Terminator Block is an exception -- it has only the TYPE byte.
689 TYPE Description Size (3-byte int) Info
690 ---- ----------- ----------------- -----------------------
691 00 Terminator (NONE) (NONE)
692 01 Sound data 2+length of data *
693 02 Sound continue length of data Voice Data
695 04 Marker 2 Marker# (2 bytes)
696 05 ASCII length of string null terminated string
697 06 Repeat 2 Count# (2 bytes)
698 07 End repeat 0 (NONE)
702 ---------------------
707 **Silence Info Format:
708 ----------------------------
709 00-01 Length of silence - 1
713 ***Extended Info Format:
714 ---------------------
715 00-01 Time Constant: Mono: 65536 - (256000000/sample_rate)
716 Stereo: 65536 - (25600000/(2*sample_rate))
722 Marker# -- Driver keeps the most recent marker in a status byte
723 Count# -- Number of repetitions + 1
724 Count# may be 1 to FFFE for 0 - FFFD repetitions
725 or FFFF for endless repetitions
726 Sample Rate -- SR byte = 256-(1000000/sample_rate)
727 Length of silence -- in units of sampling cycle
728 Compression Type -- of voice data
733 Multi DAC = 3+(# of channels) [interesting--
734 this isn't in the developer's manual]
737 ---------------------------------------------------------------------------------
738 Addendum submitted by Votis Kokavessis:
740 After some experimenting with .VOC files I found out that there is a Data Block
741 Type 9, which is not covered in the VOC.TXT file. Here is what I was able to discover
742 about this block type:
746 SIZE: 12 + length of data
747 INFO: 12 (twelve) bytes
751 Bytes 0-1: (Word) Sample Rate (e.g. 44100)
752 Bytes 2-3: zero (could be that bytes 0-3 are a DWord for Sample Rate)
753 Byte 4: Sample Size in bits (e.g. 16)
754 Byte 5: Number of channels (e.g. 1 for mono, 2 for stereo)
755 Byte 6: Unknown (equal to 4 in all files I examined)
759 -------------------------------------------------------------------------------------*/
761 /*=====================================================================================
762 **=====================================================================================
763 **=====================================================================================
764 **=====================================================================================
767 /*------------------------------------------------------------------------
768 The following is taken from the Audio File Formats FAQ dated 2-Jan-1995
769 and submitted by Guido van Rossum <guido@cwi.nl>.
770 --------------------------------------------------------------------------
771 Creative Voice (VOC) file format
772 --------------------------------
774 From: galt@dsd.es.com
776 (byte numbers are hex!)
779 Series of DATA BLOCKS (bytes 1A+) [Must end w/ Terminator Block]
781 - ---------------------------------------------------------------
786 ------ ------------------------------------------
787 00-12 "Creative Voice File"
788 13 1A (eof to abort printing of file)
789 14-15 Offset of first datablock in .voc file (std 1A 00
791 16-17 Version number (minor,major) (VOC-HDR puts 0A 01)
792 18-19 2's Comp of Ver. # + 1234h (VOC-HDR puts 29 11)
794 - ---------------------------------------------------------------
799 Data Block: TYPE(1-byte), SIZE(3-bytes), INFO(0+ bytes)
800 NOTE: Terminator Block is an exception -- it has only the TYPE byte.
802 TYPE Description Size (3-byte int) Info
803 ---- ----------- ----------------- -----------------------
804 00 Terminator (NONE) (NONE)
805 01 Sound data 2+length of data *
806 02 Sound continue length of data Voice Data
808 04 Marker 2 Marker# (2 bytes)
809 05 ASCII length of string null terminated string
810 06 Repeat 2 Count# (2 bytes)
811 07 End repeat 0 (NONE)
814 *Sound Info Format: **Silence Info Format:
815 --------------------- ----------------------------
816 00 Sample Rate 00-01 Length of silence - 1
817 01 Compression Type 02 Sample Rate
820 ***Extended Info Format:
821 ---------------------
822 00-01 Time Constant: Mono: 65536 - (256000000/sample_rate)
823 Stereo: 65536 - (25600000/(2*sample_rate))
829 Marker# -- Driver keeps the most recent marker in a status byte
830 Count# -- Number of repetitions + 1
831 Count# may be 1 to FFFE for 0 - FFFD repetitions
832 or FFFF for endless repetitions
833 Sample Rate -- SR byte = 256-(1000000/sample_rate)
834 Length of silence -- in units of sampling cycle
835 Compression Type -- of voice data
840 Multi DAC = 3+(# of channels) [interesting--
841 this isn't in the developer's manual]
843 Detailed description of new data blocks (VOC files version 1.20 and above):
845 (Source is fax from Barry Boone at Creative Labs, 405/742-6622)
847 BLOCK 8 - digitized sound attribute extension, must preceed block 1.
848 Used to define stereo, 8 bit audio
849 BYTE bBlockID; // = 8
850 BYTE nBlockLen[3]; // 3 byte length
851 WORD wTimeConstant; // time constant = same as block 1
852 BYTE bPackMethod; // same as in block 1
853 BYTE bVoiceMode; // 0-mono, 1-stereo
855 Data is stored left, right
857 BLOCK 9 - data block that supersedes blocks 1 and 8.
858 Used for stereo, 16 bit.
860 BYTE bBlockID; // = 9
861 BYTE nBlockLen[3]; // length 12 plus length of sound
862 DWORD dwSamplesPerSec; // samples per second, not time const.
863 BYTE bBitsPerSample; // e.g., 8 or 16
864 BYTE bChannels; // 1 for mono, 2 for stereo
865 WORD wFormat; // see below
866 BYTE reserved[4]; // pad to make block w/o data
867 // have a size of 16 bytes
869 Valid values of wFormat are:
871 0x0000 8-bit unsigned PCM
872 0x0001 Creative 8-bit to 4-bit ADPCM
873 0x0002 Creative 8-bit to 3-bit ADPCM
874 0x0003 Creative 8-bit to 2-bit ADPCM
875 0x0004 16-bit signed PCM
878 0x02000 Creative 16-bit to 4-bit ADPCM
880 Data is stored left, right
882 ------------------------------------------------------------------------*/