wraiff

Capsim Block Documentation

Short Description

Writes samples from an arbitrary number of input buffers to an AIFF file, which is named as a parameter.

Top
Parameters
Num Description Type Name Default Value
0 Name of output file file fileName aiff.aif
1 Number of bits int bits 8
2 Sampling Rate Hz float samplingRate 8
3 Range float range 1.0
4 Add Constant float dcOffset 0
5 Multiplication Factor float scale 1.0
6 Buffer type:0= Float, 1=Integer int bufferType 0
7 Play AIFF File:0=No,1=Yes int playFlag 0
Top
States
Num Type Name Initial Value Description
0 FILE* fp
1 int numberInputBuffers
2 int numberOutputBuffers
3 int wordSize
4 long totalSamples 0
5 long numberFrames
6 long formSizeOffset
7 long formBaseSize
8 long numberFramesOffset
9 long sndSizeOffset
10 long samplesOffset
Top

Declarations


 

        char    sample;
        float   sampf;
        long int        i;
        long int        j;
        char buffer[100];
        unsigned char   *samples_P;



Top

Initialization Code



 

if((numberInputBuffers = NO_INPUT_BUFFERS()) <= 0) {
        fprintf(stdout,"wraiff: no input buffers\n");
        return(1);
}
if((numberOutputBuffers = NO_OUTPUT_BUFFERS()) > numberInputBuffers) {
        fprintf(stdout,"wraiff: more output than input buffers\n");
        return(2);
}
switch(bufferType) {
        case FLOAT_BUFFER:
                for(i=0; i< numberInputBuffers; i++)
                        SET_CELL_SIZE_IN(i,sizeof(float));
                for(i=0; i< numberOutputBuffers; i++)
                        SET_CELL_SIZE_OUT(0,sizeof(float));
                break;
        case INTEGER_BUFFER:
                for(i=0; i< numberInputBuffers; i++)
                        SET_CELL_SIZE_IN(i,sizeof(int));
                for(i=0; i< numberOutputBuffers; i++)
                        SET_CELL_SIZE_OUT(0,sizeof(int));
                break;
        default:
                fprintf(stderr,"wraiff: Bad buffer type specified  \n");
                return(4);
                break;
}
wordSize = 1;
wordSize <<= bits-1;
/*
 *
 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 *  AIFC File Creation
 */
if(IIP_WriteAIFF((char*)fileName,NULL,NULL,NULL,(int)bits,
                        samplingRate,(int)1,
                        scale,dcOffset,range,0,
                        NULL,1,
                        &formSizeOffset,&formBaseSize,
                        &numberFramesOffset,
                        &sndSizeOffset,&samplesOffset,NULL)) {
	fprintf(stderr,"wraiff: problems writting aiff file\n");
	return(5);
}
fprintf(stderr,"formSizeOffset=%d,formBaseSize=%d,numberFramesOffset=%d,sndSizeOffset=%d,samplesOffset=%d\n",
                        formSizeOffset,formBaseSize,
                        numberFramesOffset,
                        sndSizeOffset,samplesOffset);
/*
 * Open AIFF file now that the chunks have been written 
 */
fp=fopen(fileName,"rb+");
if(fp==NULL) {
	fprintf(stderr,"wraiff: could not open aiff file to write samples\n");
	return(6);
}
/*
 * Position the file pointer where the samples should be written
 */ 
fseek(fp,samplesOffset,SEEK_SET);




Top

Main Code



 


/*
 * This mode synchronizes all input buffers
 */
for(i = MIN_AVAIL(); i>0; i--) {
                /*
                 * Calculate total number of samples inputted
                 * If more than samples return
                 */
                totalSamples++;

                for(j=0; j wordSize-1)
                                        sampf=wordSize;
			WriteSample((FILE*)fp,(int)bits,sampf);

                }

}
return(0);





Top

Wrapup Code



 

	if(totalSamples%2) totalSamples++;
	IIP_UpdateNumberFramesAIFF(fp,
                        bits,1,
                        totalSamples,
                        formSizeOffset,formBaseSize,
                        numberFramesOffset,
                        sndSizeOffset,samplesOffset);
        fclose(fp);
#if 0
        if(playFlag)
                Cs_PlayAIFF(fileName);
#endif




Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP Corporation

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/**********************************************************************
                        wraiff()
***********************************************************************
writes  samples from an arbitrary number of input buffers to an AIFF file,
which is named as a parameter.
- Data "flow-through" is implemented: if any outputs are connected,
        their values come from the correspondingly numbered input.
        (This feature is not affected by the control parameter.)
        (There cannot be more outputs than inputs.)

wraiff


writes  samples from an arbitrary number of input buffers to an AIFF file,
which is named as a parameter.
- Data "flow-through" is implemented: if any outputs are connected,
        their values come from the correspondingly numbered input.
        (This feature is not affected by the control parameter.)
        (There cannot be more outputs than inputs.)


Written by Sasan Ardalan
Date: June 15, 1993

*/