×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    6

    Reading binary file with RReadFileStream error

    Hi,

    i have a problem to reading a binary file.
    I need to read data in a 16 bit descriptor.
    I use RReadFileStream successfully but in the the last iteration fail.
    I trap it and close the stream but i obtain an ALLOC. After a lot of debugging and tracing I have uncovered that is
    caused by RReadFileStream.


    Code:
    void CSpeexEncoder::encodeFileL(const TDesC16& aInputFile, const TDesC16& aOutputFile){
    	RFs fsSession;
    	User::LeaveIfError(fsSession.Connect());
            CleanupClosePushL(fsSession);
    
    	// File to encode
    	RFileReadStream inputFileStream;
    	TInt err = inputFileStream.Open(fsSession, aInputFile, EFileRead);
    	if (err!=KErrNone){ // file does not exist - create it
    		// File Not Found
        	User::Leave(1);
    	}
    	CleanupClosePushL(inputFileStream);
    	
    	// File to decode RFileReadStream outputFileStream;
    	// ... CUT ... 
    	
    	// Buffer for reading the input file
    	HBufC16 *buffer = HBufC16::NewL(iFrameSize);
    	CleanupDeletePushL(buffer);
    	TPtr16 pBuffer = buffer->Des();
    	
    	TInt16 *in =  (TInt16 *)User::Alloc(iFrameSize*sizeof(TInt16));
    	CleanupDeletePushL(in);
    	
    	while (true){
    
    		//Read a 16 bits/sample audio frame
    		// Using RReadFileStream::ReadL(TDes16 &aDes, TInt aLength);
    		TRAP(error,inputFileStream.ReadL(pBuffer, iFrameSize));
    		if (error) { //EOF
    			break;
    		}
    				
    		nbBytes = buffer->Length();
    		if (nbBytes==0) {
    			break;
    		}
    		
    		for (i=0;i<nbBytes; i++){
    			in[i]= (TInt16)(*buffer)[i];
             	}
    		
    		// work with the data readed
    		// ... CUT ... 
    		
    	}
    	
    	//in
    	CleanupStack::PopAndDestroy();
    	//buffer
    	CleanupStack::PopAndDestroy();
    	// outputFileStream
    	CleanupStack::PopAndDestroy();
    	// inputFileStream
    	CleanupStack::PopAndDestroy(); 
    	// fsSession
    	CleanupStack::PopAndDestroy(); 	
    }

    I have tried to get the file size to handle the last execution but the program terminate with an Kern Exec 0.

    I have tried also (with same result)
    Code:
       TInt fileSize=0;
        TInt pos=0;
        fileInput.Seek(ESeekEnd,pos);
        fileInput.Seek(ESeekCurrent,pos);
        fileSize = pos;

    I use Symbian 9.1 S60 3rd MR.

    In alternative how can i read 16bit with RFile::Read ???
    Using STDLIB the code is
    Code:
    fread(in, sizeof(short), FRAME_SIZE, fileInput);
    where in is short in[FRAME_SIZE];
    but RFile::Read read only TDes8 and i can't and wan't use stdlib.


    Thanks,
    Maucem

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    6

    Re: Reading binary file with RReadFileStream error (solved)

    Hi,

    i solved my problem but i don't know why RFileReadStream don't release the memory allocated for their buffer.

    I use RFile in the final code, with minimal changing. This is the chunk of the code


    Code:
    // Buffer for reading the input file
    HBufC8 *buffer = HBufC8::NewL(iFrameSize*sizeof(TInt16));
    CleanupDeletePushL(buffer);
    TPtr8 pBuffer = buffer->Des();
    	
    // Array of Short
    TInt16 *in =  (TInt16 *)User::Alloc(iFrameSize*sizeof(TInt16));
    CleanupDeletePushL(in);
    	
    ... CUT ...
    	
    while (1) {
        // using RFile::Read (TDes8, TInt)
        err = inputFile.Read(pBuffer, iFrameSize*sizeof(TInt16));
    	
       // break condition
    		
       // Copy the 16 bits values from char->short->float 
       // so Speex can work on them			
       for (i=0, j=0;i<nbBytes;i=i+2, j++){
          in[j] = (TInt16) ( 0x00FF & (*buffer)[i] | 0x00FF & (*buffer)[i+1])<<8;
       }	
    	
       ... CUT ...
    }
    	
    // Releasing memory

    bye

Similar Threads

  1. Replies: 13
    Last Post: 2007-12-07, 11:21
  2. My BuilderX (with S60 SDK 2.1.NET MS version) cannot build ARMI UREL
    By danielvidonyi@hotmail.com in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2006-05-04, 21:30
  3. reading bits from a binary file
    By vodkaloon in forum Symbian
    Replies: 2
    Last Post: 2004-11-25, 15:15
  4. camera app compilation problems
    By basarim in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2003-12-31, 18:16
  5. nokia 7210 modem via IR doesn't work !
    By oussamaaiadi in forum PC Suite API and PC Connectivity SDK
    Replies: 1
    Last Post: 2003-03-06, 10:46

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •