Innovative Integration
 
Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Howto go to code "case pmRepeat:" in play()-fn of

 
Post new topic   Reply to topic    II Support Forum Index -> SBC6713e
View previous topic :: View next topic  
Author Message
tejpratap



Joined: 22 Feb 2009
Posts: 20
Location: Bangalore/India

PostPosted: Fri Mar 13, 2009 9:36 pm    Post subject: Howto go to code "case pmRepeat:" in play()-fn of Reply with quote

when using the Dataplayer class for playing a file, it works fine. But still there is a problem when I want to use the 'Mode' - property of the class wherein I am setting the mode as "Player.Mode(DataPlayer::pmRepeat)". after setting the mode like above in the host program, when I execute it , the "play"-function of the Dataplayer never reaches to the line:

switch (FMode) :

so that case 'pmRepeat' can be executed. I observed that it is because value of 'residual' is always 0 in the line :

if(residual)
{
.......
}

because the gcount() method returns the same value which was assigned to the variable 'residual' during the start of the play() -function of the Dataplayer class in each call to play()-fn till my playback-file is read and played back completely.

Please tell me how to reach to the line of code :

case pmRepeat:

so that I can use this property of the Mode of the Dataplyer.
Question

_________________
tej pratap
Back to top
View user's profile Send private message Send e-mail
csmith
Site Admin


Joined: 13 Apr 2006
Posts: 55

PostPosted: Mon Mar 16, 2009 10:28 am    Post subject: Reply with quote

The use of residual for the EOF test is incorrect, this is a bug in the code. Instead we should be using feof() to detect the EOF condition there. In addition the EOF test is moved to be right after the read(). I also set FPlayed to 0 in the repeat test to avoid increasing that number indefinitely.

Note - if you have included packet headers in your playback file, do not use pmZero mode. The zeroed header makes an illegal packet.

Code:

size_t DataPlayer::Play(int * data, size_t size)
{
    if (!FOpened || !FEnabled || !size || !mFile)
        return 0;

    streamsize residual = size*sizeof(int);
    char * dst = reinterpret_cast<char *>(data);

    while (residual)
        {
      size_t read = fread(dst, 1, residual, mFile);
      // Handle EOF condition
      if (feof(mFile))
         {
         switch (FMode)
            {
            case pmStop:
               return (size*sizeof(int)-residual)/sizeof(int);

            case pmRepeat:
               fseek(mFile, 0, SEEK_SET);
                                        FPlayed = 0;
               break;

            case pmZero:
               memset(dst, 0, residual);
               return size;
            }
         }
           
      residual -= read;
      dst += read;
      FPlayed += read;
      }

   return size;
}


This code is a little different than the version you are have. This fix will get put into the next Malibu release.

If you want to get the change faster, include DataPlayer_Mb.cpp in your application project, and make the changes above. Use feof() in the condition and rebuild your project, and you should see repeat mode working.

_________________
Chris Smith
Innovative Integration
csmith@innovative-dsp.com
Back to top
View user's profile Send private message
tejpratap



Joined: 22 Feb 2009
Posts: 20
Location: Bangalore/India

PostPosted: Fri Apr 30, 2010 2:27 am    Post subject: Reply with quote

Dear Sir,
I have tried to incorporate the provided code into the file DataPlayer_Mb.cpp which I included in the application project and then built the project. But, I am receiving the following errors:

---------------------------------------------------------------------------------
[C++ Error] DataPlayer_Mb.cpp(191): E2034 Cannot convert '_STL::ifstream' to 'FILE *'
[C++ Error] DataPlayer_Mb.cpp(191): E2342 Type mismatch in parameter '__stream' (wanted 'FILE *', got '_STL::ifstream')
[C++ Error] DataPlayer_Mb.cpp(195): E2288 Pointer to structure required on left side of -> or ->*
[C++ Error] DataPlayer_Mb.cpp(209): E2034 Cannot convert '_STL::ifstream' to 'FILE *'
[C++ Error] DataPlayer_Mb.cpp(209): E2342 Type mismatch in parameter '__stream' (wanted 'FILE *', got '_STL::ifstream')
-----------------------------------------------------------------------------------

Then I tried to put this code in the following way:

====================================================

size_t DataPlayer::Play(int * data, size_t size)
{
if (!FOpened || !FEnabled || !size || !mFile)
return 0;

std::streamsize residual = size*sizeof(int);
char * dst = reinterpret_cast<char *>(data);

while (residual)
{
// size_t read = fread(dst, 1, residual, mFile);
mFile.read(dst, residual);

// Handle EOF condition
// if (feof(mFile))

if(mFile.eof())
{
switch (FMode)
{
case pmStop:
return (size*sizeof(int)-residual)/sizeof(int);

case pmRepeat:
mFile.seekg(0,std::ios::beg);
FPlayed = 0;
/*
fseek(mFile, 0, SEEK_SET);
FPlayed = 0;
*/
break;

case pmZero:
memset(dst, 0, residual);
return size;
}
}

// residual -= read;
residual -= mFile.gcount();
// dst += read;
dst += mFile.gcount();
// FPlayed += read;
FPlayed += mFile.gcount();
}

return size;
}

=====================================================

1) Am I correct in doing so to implement your new code?

2) When I debug the code, I find that the program returns at the following line itself inside the play() function:

size_t DataPlayer::Play(int * data, size_t size)
{
if (!FOpened || !FEnabled || !size || !mFile)
return 0;

because, FOpened=false and mFile shows NULL in watch.

Why is it so, when the file was successfully opened which I can see when the program was executing inside Player.start() before calling play() ?

With regards
tej pratap

_________________
tej pratap
Back to top
View user's profile Send private message Send e-mail
csmith
Site Admin


Joined: 13 Apr 2006
Posts: 55

PostPosted: Fri Apr 30, 2010 9:58 am    Post subject: Reply with quote

If Start() could not open the file, you could get this condition. Otherwise, the only way I see that this could occur is if you had called Stop() before Play(). This will close the file and reset FOpened.
_________________
Chris Smith
Innovative Integration
csmith@innovative-dsp.com
Back to top
View user's profile Send private message
tejpratap



Joined: 22 Feb 2009
Posts: 20
Location: Bangalore/India

PostPosted: Sat May 01, 2010 6:58 am    Post subject: Reply with quote

Dear sir,
My playback code earlier was working ok except for the situations of
playback when I wanted to use the line of code " switch (FMode) :" for cases of 'case pmZero: ' and 'case pmRepeat: '. But I was not able to reach to the line of code " switch (FMode) :" as I have written in my first mail under this topic. Then as suggested by you, I replaced the play() code only keeping the other parts of the playback code same. Hence, there is no question of calling Stop() before Play(). Also, I have not changed the Start() code or a call to this . Start() is working fine now also as earlier as can be monitored through 'Watch'. Then Why I am getting the errors ? Crying or Very sad

with regards
tej pratap

_________________
tej pratap
Back to top
View user's profile Send private message Send e-mail
csmith
Site Admin


Joined: 13 Apr 2006
Posts: 55

PostPosted: Mon May 03, 2010 8:17 am    Post subject: Reply with quote

If Start() is setting those variables, something has to be changing them before you call Play(), or they would be in the proper state. If this is not happening in Stop(), then you may have to debug to see where this data is getting overwritten improperly.

Alternatively, you could look at the more recent Malibu releases, which have rewritten this class (primarily to accommodate other OSes).

_________________
Chris Smith
Innovative Integration
csmith@innovative-dsp.com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    II Support Forum Index -> SBC6713e (GMT - 8 Hours)
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

© Copyright 2006-2008 Innovative Integration
Powered by phpBB © 2001, 2002 phpBB Group
Based on iCGstation v1.0 Template By Ray © 2003, 2004 iOptional