1 /****************************************************************************
3 * ____ ___ ____ __ ______ ___ ____ ____/ / *
4 * / __ `__ \/ __ `/ |/ / __ `__ \/ __ \/ __ / *
5 * / / / / / / /_/ /> </ / / / / / /_/ / /_/ / *
6 * /_/ /_/ /_/\__,_/_/|_/_/ /_/ /_/\____/\__,_/ *
8 * Copyright (c) 2008, Mukunda Johnson (mukunda@maxmod.org) *
10 * Permission to use, copy, modify, and/or distribute this software for any *
11 * purpose with or without fee is hereby granted, provided that the above *
12 * copyright notice and this permission notice appear in all copies. *
14 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES *
15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF *
16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR *
17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES *
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN *
19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *
20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
21 ****************************************************************************/
23 // information from ITTECH.TXT
33 #include "samplefix.h"
36 #define vstr_it_div "ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n"
37 #define vstr_it_instr_top "ÚÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n"
38 #define vstr_it_instr_head "³INDEX³VOLUME³ NNA ³ ENV ³ NAME ³\n"
39 #define vstr_it_instr_slice "ÃÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÅÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´\n"
40 #define vstr_it_instr "³%3i ³ %3i%% ³ %3s ³ %s%s%s ³ %-26s³\n"
41 #define vstr_it_instr_bottom "ÀÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n"
43 #define vstr_it_samp_top "ÚÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÄÂÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\n"
44 #define vstr_it_samp_head "³INDEX³VOLUME³DVOLUME³ LOOP ³ MID-C ³ NAME ³\n"
45 #define vstr_it_samp_slice "ÃÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÄÅÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´\n"
46 #define vstr_it_samp "³%3i ³ %3i%% ³ %3i%% ³ %4s ³%6ihz ³ %-26s³\n"
47 #define vstr_it_samp_bottom "ÀÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÄÁÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\n"
49 #define vstr_it_pattern " \x0e %2i"
51 #define vstr_it_div "--------------------------------------------\n"
52 #define vstr_it_instr_top vstr_it_div
53 #define vstr_it_instr_head " INDEX VOLUME NNA ENV NAME\n"
54 //#define vstr_it_instr_slice ""
55 #define vstr_it_instr " %-3i %3i%% %3s %s%s%s %-26s \n"
56 #define vstr_it_instr_bottom vstr_it_div
58 #define vstr_it_samp_top vstr_it_div
59 #define vstr_it_samp_head " INDEX VOLUME DVOLUME LOOP MID-C NAME \n"
60 //#define vstr_it_samp_slice ""
61 #define vstr_it_samp " %-3i %3i%% %3i%% %4s %6ihz %-26s \n"
62 #define vstr_it_samp_bottom vstr_it_div
64 #define vstr_it_pattern " * %2i"
67 bool Load_IT_Envelope( Instrument_Envelope* env, bool unsign )
76 bool env_enabled=false;
77 bool env_filter=false;
79 memset( env, 0, sizeof( Instrument_Envelope ) );
104 env->env_filter=env_filter;
108 if( node_count != 0 )
111 env->node_count = node_count;
114 env->loop_start=read8();
115 env->loop_end=read8();
123 env->sus_start=read8();
124 env->sus_end=read8();
130 for( x = 0; x < 25; x++ )
132 env->node_y[x] = read8();
134 env->node_y[x] += 32;
135 env->node_x[x] = read16();
138 read8(); // unused byte
139 env->env_enabled = env_enabled;
143 int Load_IT_Instrument( Instrument* inst, bool verbose, int index )
148 memset( inst, 0, sizeof( Instrument ) );
154 a=read16(); if( a > 255 ) a = 255;
155 inst->fadeout =(u8)a;
157 inst->global_volume =read8();
159 a = (a&128) | ((a&127)*2 > 127 ? 127 : (a&127)*2);
161 inst->random_volume =read8();
163 for( x = 0; x < 26; x++ )
164 inst->name[x] = read8();
167 for( x = 0; x < 120; x++ )
168 inst->notemap[x] = read16();
172 Load_IT_Envelope( &inst->envelope_volume, false );
173 inst->env_flags |= inst->envelope_volume.env_valid ? 1 : 0;
174 inst->env_flags |= inst->envelope_volume.env_enabled ? 8 : 0;
176 Load_IT_Envelope( &inst->envelope_pan, true );
177 inst->env_flags |= inst->envelope_pan.env_enabled ? 2 : 0;
179 Load_IT_Envelope( &inst->envelope_pitch, true );
180 inst->env_flags |= inst->envelope_pitch.env_enabled ? 4 : 0;
184 printf( vstr_it_instr, \
186 (inst->global_volume*100)/128, \
187 ((inst->nna==0)?"CUT":((inst->nna==1)?"CON":((inst->nna==2)?"OFF":((inst->nna==3)?"FAD":"???")))), \
188 (inst->env_flags&8)?"V":"-", \
189 (inst->env_flags&2)?"P":"-", \
190 (inst->env_flags&4)?"T":"-", \
193 /* printf( "%i%% ", (inst->global_volume*100) / 128 );
197 printf( "%s ", "CUT" ); break;
199 printf( "%s ", "OFF" ); break;
201 printf( "%s ", "CONT" ); break;
203 printf( "%s ", "FADE" ); break;
205 if( (!(inst->env_flags & 2)) && (!(inst->env_flags & 4)) && (!(inst->env_flags & 8)) )
211 if( inst->env_flags & 8)
213 if( inst->env_flags & 2)
215 if( inst->env_flags & 4)
219 printf( "%s\n", inst->name );*/
226 void Create_IT_Instrument( Instrument* inst, int sample )
230 memset( inst, 0, sizeof( Instrument ) );
232 inst->global_volume =128;
234 for( x = 0; x < 120; x++ )
235 inst->notemap[x] = x+sample*256;
238 int Load_IT_Sample( Sample* samp )
243 bool samp_unsigned=false;
252 memset( samp, 0, sizeof( Sample ) );
253 samp->msl_index = 0xFFFF;
255 if( read32() != 'SPMI' )
256 return ERR_UNKNOWNSAMPLE;
257 for( x = 0; x < 12; x++ ) // dos filename
258 samp->filename[x] = read8();
260 return ERR_UNKNOWNSAMPLE;
261 samp->global_volume = read8();
263 samp->it_compression = a & 8 ? 1 : 0;
267 samp->default_volume = read8();
268 for( x = 0; x < 26; x++ )
269 samp->name[x] = read8();
271 samp->default_panning = read8();
272 samp->default_panning = (((samp->default_panning&127) == 64) ? 127 : (samp->default_panning<<1)) | (samp->default_panning&128);
275 samp_length = read32();
280 samp->frequency = c5spd;
281 samp->sample_length = samp_length;
282 samp->loop_start = loop_start;
283 samp->loop_end = loop_end;
285 skip8( 8 ); // susloop start/end
286 data_address = read32();
287 samp->vibspeed = read8();
288 samp->vibdepth = read8();
289 samp->vibrate = read8();
290 samp->vibtype = read8();
291 samp->datapointer = data_address;
298 samp->loop_start = loop_start;
299 samp->loop_end = loop_end;
305 samp->format = (bit16 ? SAMPF_16BIT : 0) | (samp_unsigned ? 0 : SAMPF_SIGNED );
306 if( samp->sample_length == 0 ) samp->loop_type = 0;
310 int Load_IT_Sample_CMP( u8 *p_dest_buffer, int samp_len, u16 cmwt, bool bit16 );
311 int Load_IT_SampleData( Sample* samp, u16 cwmt )
315 if( samp->sample_length == 0 ) return 0;
316 if( samp->format & SAMPF_16BIT )
317 samp->data = (u16*)malloc( (u32)(samp->sample_length)*2 );
319 samp->data = (u8*)malloc( (u32)(samp->sample_length) );
321 if( !samp->it_compression )
324 for( x = 0; x < samp->sample_length; x++ )
326 if( samp->format & SAMPF_16BIT )
328 if( !(samp->format & SAMPF_SIGNED) )
330 a = (unsigned short)read16();
334 a = (signed short)read16();
337 ((u16*)samp->data)[x] = (u16)a;
341 if( !(samp->format & SAMPF_SIGNED) )
343 a = (unsigned char)read8();
347 a = (signed char)read8();
350 ((u8*)samp->data)[x] = (u8)a;
357 Load_IT_Sample_CMP( samp->data, samp->sample_length, cwmt, (bool)(samp->format & SAMPF_16BIT) );
363 int Empty_IT_Pattern( Pattern *patt ) {
366 memset( patt, 0, sizeof( Pattern ) );
368 for( x = 0; x < patt->nrows*MAX_CHANNELS; x++ ) {
369 patt->data[x].note = 250; // special clears for vol¬e
370 patt->data[x].vol = 255;
375 int Load_IT_Pattern( Pattern* patt )
383 u8 old_maskvar[MAX_CHANNELS];
384 u8 old_note[MAX_CHANNELS];
385 u8 old_inst[MAX_CHANNELS];
386 u8 old_vol[MAX_CHANNELS];
387 u8 old_fx[MAX_CHANNELS];
388 u8 old_param[MAX_CHANNELS];
390 memset( patt, 0, sizeof( Pattern ) );
393 patt->nrows = read16();
396 patt->clength = clength;
398 for( x = 0; x < patt->nrows*MAX_CHANNELS; x++ )
400 patt->data[x].note = 250; // special clears for vol¬e
401 patt->data[x].vol = 255;
405 // DECOMPRESS IT PATTERN
407 for( x = 0; x < patt->nrows; x++ )
409 GetNextChannelMarker:
410 chanvar = read8(); // Read byte into channelvariable.
411 if( chanvar == 0 ) // if(channelvariable = 0) then end of row
414 chan = (chanvar-1) & 63; // Channel = (channelvariable-1) & 63
415 if( chan >= MAX_CHANNELS )
416 return ERR_MANYCHANNELS;
418 if( chanvar & 128 ) // if(channelvariable & 128) then read byte into maskvariable
419 old_maskvar[chan] = read8();
421 maskvar = old_maskvar[chan];
423 if( maskvar & 1 ) // if(maskvariable & 1), then read note. (byte value)
425 old_note[chan] = read8();
426 patt->data[x*MAX_CHANNELS+chan].note = old_note[chan];
429 if( maskvar & 2 ) // if(maskvariable & 2), then read instrument (byte value)
431 old_inst[chan] = read8();
432 patt->data[x*MAX_CHANNELS+chan].inst = old_inst[chan];
435 if( maskvar & 4 ) // if(maskvariable & 4), then read volume/panning (byte value)
437 old_vol[chan] = read8();
438 patt->data[x*MAX_CHANNELS+chan].vol = old_vol[chan];
441 if( maskvar & 8 ) // if(maskvariable & 8), then read command (byte value) and commandvalue
443 old_fx[chan] = read8();
444 patt->data[x*MAX_CHANNELS+chan].fx = old_fx[chan];
445 old_param[chan] = read8();
446 patt->data[x*MAX_CHANNELS+chan].param = old_param[chan];
449 if( maskvar & 16 ) // if(maskvariable & 16), then note = lastnote for channel
450 patt->data[x*MAX_CHANNELS+chan].note = old_note[chan];
451 if( maskvar & 32 ) // if(maskvariable & 32), then instrument = lastinstrument for channel
452 patt->data[x*MAX_CHANNELS+chan].inst = old_inst[chan];
453 if( maskvar & 64 ) // if(maskvariable & 64), then volume/pan = lastvolume/pan for channel
454 patt->data[x*MAX_CHANNELS+chan].vol = old_vol[chan];
455 if( maskvar & 128 ) // if(maskvariable & 128), then {
457 patt->data[x*MAX_CHANNELS+chan].fx = old_fx[chan]; // command = lastcommand for channel and
458 patt->data[x*MAX_CHANNELS+chan].param = old_param[chan];// commandvalue = lastcommandvalue for channel
460 goto GetNextChannelMarker;
466 int Load_IT( MAS_Module* itm, bool verbose )
482 memset( itm, 0, sizeof( MAS_Module ) );
484 if( read32() != 'MPMI' )
485 return ERR_INVALID_MODULE;
486 for( x = 0; x < 28; x++ )
487 itm->title[x] = read8();
488 itm->order_count = (u16)read16();
489 itm->inst_count = (u8)read16();
490 itm->samp_count = (u8)read16();
491 itm->patt_count = (u8)read16();
493 cmwt = read16(); // upward compatible
494 //skip8( 4 ); // created with tracker / upward compatible
495 w = read16(); // flags
497 itm->inst_mode = instr_mode = w & 4;
498 itm->freq_mode = w & 8;
499 itm->old_effects = w & 16;
500 itm->link_gxx = w & 32;
501 skip8( 2 ); // special
502 itm->global_volume = read8();
503 skip8( 1 ); // mix volume
504 itm->initial_speed = read8();
505 itm->initial_tempo = read8();
509 printf( vstr_it_div );
510 printf( "Loading IT, \"%s\"\n", itm->title );
511 printf( vstr_it_div );
512 printf( "#Orders......%i\n", itm->order_count );
513 printf( "#Instr.......%i\n", itm->inst_count );
514 printf( "#Samples.....%i\n", itm->samp_count );
515 printf( "#Patterns....%i\n", itm->patt_count );
516 printf( "Stereo.......%s\n", itm->stereo ? "Yes" : "No" );
517 printf( "Slides.......%s\n", itm->freq_mode ? "Linear" : "Amiga" );
518 printf( "Old Effects..%s\n", itm->old_effects ? "Yes" : "No" );
519 printf( "Global Vol...%i%%\n", (itm->global_volume*100)/128 );
520 printf( "Speed........%i\n", itm->initial_speed );
521 printf( "Tempo........%i\n", itm->initial_tempo );
522 printf( "Instruments..%s\n", instr_mode ? "Yes" : "Will be supplied" );
523 printf( vstr_it_div );
525 skip8( 12 ); // SEP, PWD, MSGLENGTH, MESSAGE OFFSET, [RESERVED]
526 for( x = 0; x < 64; x++ )
529 if( x < MAX_CHANNELS )
530 itm->channel_panning[x] = b*4 > 255 ? 255 : b*4; // map 0->64 to 0->255
532 for( x = 0; x < 64; x++ )
535 if( x < MAX_CHANNELS )
536 itm->channel_volume[x] = b;
538 for( x = 0; x < itm->order_count; x++ )
539 itm->orders[x] = read8();
541 parap_inst = (u32*)malloc( itm->inst_count * sizeof( u32 ) );
542 parap_samp = (u32*)malloc( itm->samp_count * sizeof( u32 ) );
543 parap_patt = (u32*)malloc( itm->patt_count * sizeof( u32 ) );
545 for( x = 0; x < itm->inst_count; x++ )
546 parap_inst[x] = read32();
547 for( x = 0; x < itm->samp_count; x++ )
548 parap_samp[x] = read32();
549 for( x = 0; x < itm->patt_count; x++ )
550 parap_patt[x] = read32();
552 itm->samples = (Sample*)malloc( itm->samp_count * sizeof( Sample ) );
553 itm->patterns = (Pattern*)malloc( itm->patt_count * sizeof( Pattern ) );
557 itm->instruments = (Instrument*)malloc( itm->inst_count * sizeof( Instrument ) );
560 printf( "Loading Instruments...\n" );
561 printf( vstr_it_instr_top );
562 printf( vstr_it_instr_head );
563 #ifdef vstr_it_instr_slice
564 printf( vstr_it_instr_slice );
566 //printf( "INDEX VOLUME NNA ENV NAME\n" );
570 for( x = 0; x < itm->inst_count; x++ )
573 // printf( "%i ", x+1 );
574 file_seek_read( parap_inst[x], SEEK_SET );
575 Load_IT_Instrument( &itm->instruments[x], verbose, x );
580 printf( vstr_it_instr_bottom );
586 printf( "Loading Samples...\n" );
587 printf( vstr_it_samp_top );
588 printf( vstr_it_samp_head );
589 #ifdef vstr_it_samp_slice
590 printf( vstr_it_samp_slice );
592 //printf( "INDEX VOLUME DVOLUME LOOP MID-C NAME\n" );
596 for( x = 0; x < itm->samp_count; x++ )
598 file_seek_read( parap_samp[x], SEEK_SET );
599 Load_IT_Sample( &itm->samples[x] );
602 printf( vstr_it_samp, x+1, (itm->samples[x].global_volume * 100) / 64, (itm->samples[x].default_volume * 100) / 64, itm->samples[x].loop_type == 0 ? "None" : (itm->samples[x].loop_type == 1 ? "Forw" : "BIDI"), itm->samples[x].frequency, itm->samples[x].name );
603 //printf( "%i %i%% %i%% %s %ihz %s\n", x+1, (itm->samples[x].global_volume*100) / 64, (itm->samples[x].default_volume*100) / 64, itm->samples[x].loop_type == 0 ? "None" : (itm->samples[x].loop_type == 1 ? "Yes" : "BIDI"), itm->samples[x].frequency, itm->samples[x].name );
609 printf( vstr_it_samp_bottom );
616 printf( "Adding Instrument Templates...\n" );
617 printf( vstr_it_div );
619 itm->inst_count = itm->samp_count;
620 itm->instruments = (Instrument*)malloc( itm->inst_count * sizeof( Instrument ) );
622 for( x = 0; x < itm->samp_count; x++ )
626 printf( " * %2i", x+1 );
634 Create_IT_Instrument( &itm->instruments[x], x+1 );
639 printf( (((x+1)%15)==0)?"":"\n" );
640 printf( vstr_it_div );
646 printf( "Reading Patterns...\n" );
647 printf( vstr_it_div );
652 for( x = 0; x < itm->patt_count; x++ )
654 file_seek_read( parap_patt[x], SEEK_SET );
655 if( parap_patt[x] != 0 )
659 printf( vstr_it_pattern, x+1 );
667 Load_IT_Pattern( &itm->patterns[x] );
672 Empty_IT_Pattern( &itm->patterns[x] );
673 //memset( &itm->patterns[x], 0, sizeof( Pattern ) );
682 printf( vstr_it_div );
683 printf( "Loading Sample Data...\n" );
686 for( x = 0; x < itm->samp_count; x++ )
688 file_seek_read( itm->samples[x].datapointer, SEEK_SET );
689 Load_IT_SampleData( &itm->samples[x], cmwt );
694 printf( vstr_it_div );
704 /* * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE
706 -The following sample decompression code is based on CHIBITRACKER's code (http://chibitracker.berlios.de) which is based on xmp's code.(http://xmp.helllabs.org) which is based in openCP code.
708 * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE */
710 int Load_IT_CompressedSampleBlock( u8** buffer )
715 (*buffer) = (u8*)malloc( size+4 );
720 for( x = 0; x < size; x++ )
721 (*buffer)[x] = read8();
725 int Load_IT_Sample_CMP( u8 *p_dest_buffer, int samp_len, u16 cmwt, bool bit16 )
728 u16 block_length; // length of compressed data block in samples
729 u16 block_position; // position in block
730 u8 bit_width; // actual "bit width"
731 u32 aux_value; // value read from file to be processed
732 s16 d1, d2; // integrator buffers (d2 for it2.15)
734 s8 v8; // sample value
735 s16 v16; // sample value 16 bit
736 bool it215; // is this an it215 module?
744 u8 *dest8_write = (u8 *)p_dest_buffer;
745 u16 *dest16_write = (u16 *)p_dest_buffer;
747 nbits = bit16 ? 16 : 8;
748 dsize = bit16 ? 4 : 3;
749 for (i=0;i<samp_len;i++)
750 p_dest_buffer[i]=128;
756 // now unpack data till the dest buffer is full
760 // read a new block of compressed data and reset variables
761 Load_IT_CompressedSampleBlock( &c_buffer );
764 block_length = (samp_len < 0x4000) ? samp_len : 0x4000;
766 block_length = (samp_len < 0x8000) ? samp_len : 0x8000;
768 bit_width = nbits+1; // start with width of 9 bits
769 d1 = d2 = d18=d28=0; // reset integrator buffers
772 // now uncompress the data block
773 while ( block_position < block_length ) {
775 aux_value = readbits( c_buffer, bit_readpos, bit_width ); // read bits
776 bit_readpos+=bit_width;
778 if ( bit_width < 7 ) { // method 1 (1-6 bits)
782 if ( (signed)aux_value == (1 << (bit_width - 1)) ) { // check for "100..."
784 aux_value = readbits( c_buffer, bit_readpos, dsize )+1; //read_n_bits_from_IT_compressed_block(3) + 1; // yes -> read new width;
785 bit_readpos += dsize;
786 bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1;
788 continue; // ... next value
793 if ( aux_value == ((u32)1 << ((u32)bit_width - 1)) ) { // check for "100..."
795 aux_value = readbits( c_buffer, bit_readpos, dsize )+1; //read_n_bits_from_IT_compressed_block(3) + 1; // yes -> read new width;
796 bit_readpos += dsize;
797 bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1;
799 continue; // ... next value
803 } else if ( bit_width < nbits + 1 ) { // method 2 (7-8 bits)
807 border = (0xFFFF >> ((nbits+1) - bit_width)) - (nbits/2);
808 // lower border for width chg
810 if ( (int)aux_value > (int)border && (int)aux_value <= ((int)border + nbits) ) {
812 aux_value -= border; // convert width to 1-8
813 bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1;
815 continue; // ... next value
820 border = (0xFF >> ((nbits+1) - bit_width)) - (nbits/2);
821 // lower border for width chg
823 if ( aux_value > border && aux_value <= (border + nbits) ) {
825 aux_value -= border; // convert width to 1-8
826 bit_width = (aux_value < bit_width) ? aux_value : aux_value + 1;
828 continue; // ... next value
832 } else if ( bit_width == nbits+1 ) { // method 3 (9 bits)
834 if ( aux_value & (1<<nbits) ) { // bit 8 set?
836 bit_width = (aux_value + 1) & 0xff; // new width...
837 continue; // ... and next value
840 } else { // illegal width, abort
843 free( c_buffer ); c_buffer=NULL; }
844 return ERR_UNKNOWNSAMPLE;
847 // now expand value to signed byte
848 if ( bit_width < nbits ) {
850 tmp_shift = nbits - bit_width;
853 v16=(aux_value << tmp_shift);
858 v8=(aux_value << tmp_shift);
866 v16 = (s16) aux_value;
873 // integrate upon the sample values
877 // ... and store it into the buffer
878 *(dest16_write++) = (it215 ? d2+32768 : d1+32768);
882 // integrate upon the sample values
886 // ... and store it into the buffer
887 *(dest8_write)++ = (it215 ? (int)d28+128 : (int)d18+128);
893 // now subtract block lenght from total length and go on
895 free( c_buffer ); c_buffer=NULL; }
896 samp_len -= block_length;