Recent

Author Topic: Playing Sound Forward and Backwards using mciSendCommand - or by other means  (Read 8707 times)

dmudie

  • New member
  • *
  • Posts: 9
Good Morning,

I was very excited to stumble across Lazarus several days ago.  I was a big fan of Delphi... using every version from 1 to 6.  It's been a while, so I'm a bit rusty, but it is coming back.

I am working on a project that works similarly to transcription software - a user listens to audio files and controls the playback using a foot pedal (USB Infinity brand). 

My Question:

I miss the multimedia control from Delphi.  I have spent quite a bit of time learning how to play the audio files.  I have looked at acs, uos, audorra and bass.  I didn't have any success installing any of them, so I moved on to using windows api functions.  (I am not concerned about portability and I'm not concerned about what file type I use for the audio file)

I was able to use the mciSendCommand function.  With it, I have been able to perform the functions: play, pause, stop, determine length, determine position, set volume and determine volume.

I would like to be able to play the file backwards (from the current position) so that the user can easily reset the position to re-listen to a portion of the file.  I would also like to be able to speed up and slow down the rate of play to help the user 'scrub' to a position. 

I haven't been able to find out how to do this (or if its possible) with the mciSendCommand function.  The functionality seems to be available for some video types, but not indicated in the documentation for audio files.  If anyone has some input, I would really appreciate it.  In addition, if you have an alternative suggestion for how to play the files, I would appreciate hearing it.

Thank you,

David

Zittergie

  • Full Member
  • ***
  • Posts: 114
    • XiX Music Player
Hi,
You can take a look at the bass libraries (http://www.un4seen.com).
I use it in XiXMusicPlayer (source available at https://sourceforge.net/projects/xixmusicplayer/)
Be the difference that makes a difference

RAW

  • Hero Member
  • *****
  • Posts: 868
Quote
(source available at https://sourceforge.net/projects/xixmusicplayer/)
Nice screenshots !!!
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

dmudie

  • New member
  • *
  • Posts: 9
I previously tried Bass and had problems.  After your suggestion I have taken a more in depth look at it.  I have a better understanding and am closer to getting it working.

Thank you for your suggestion. 

molly

  • Hero Member
  • *****
  • Posts: 2330
I was able to use the mciSendCommand function.  With it, I have been able to perform the functions: play, pause, stop, determine length, determine position, set volume and determine volume.

I would like to be able to play the file backwards (from the current position) so that the user can easily reset the position to re-listen to a portion of the file.  I would also like to be able to speed up and slow down the rate of play to help the user 'scrub' to a position. 
Do you really seek the functionality to play audio in reverse, or just seeking a method for mci to set the current play position (inside the wav) quickly ?

In case the latter:
Code: Pascal  [Select][+][-]
  1. var
  2.   FPCommand      : array[0..128] of char;
  3.   milliseconds : integer;
  4. begin
  5.     milliseconds := .... some number that lies in the .wav file play length (in milliseconds).
  6.     FPcommand := 'play MediaFile from ' + IntToStr(milliseconds) + #0;
  7.     Ferror := mciSendString(FPcommand, nil, 0, IntPtr(0));
  8.     print_mcierror(FError);
  9. end;
  10.  
Where "MediaFile" is an alias for the file opened by mci. The print_mcierrorr() function is just a wrapper around mciGetErrorString() that i made myself (so can be omitted/replaced by yours).
« Last Edit: October 31, 2016, 09:34:18 pm by molly »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
hello,
I have looked at acs, uos, audorra and bass. I didn't have any success installing any of them, so I moved on to using windows api functions.
What is wrong with the install of acs, uos. I have no problem to install them on windows 7   Lazarus 1.6 32 bits.

Friendly, J.P
« Last Edit: November 01, 2016, 01:01:35 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

dmudie

  • New member
  • *
  • Posts: 9
Good Afternoon,

Thanks to everyone for your replies.

In order:

Zittergie: Thanks for the suggestion of Bass.  I was able to get it to work.  It took a while, but it's working... at least as a proof of concept.

molly: I would like to have it play in reverse.  It makes it easier for a transcriber to know how far to back the recording up if they miss something.

Jurassic Pork:  After your comment I decided to try ACS again.  I also removed the 64 bit version of Lazarus and installed the 32 bit version.  Finally, after Googling some errors, I discovered that the version of ACS I had was not official.  With all that being straightened out, I was able to install ACS and get it to work playing a file.

I like how easy it is to use ACS to play an audio file.  As I indicated earlier, portability to other operating system isn't a huge deal, but if I have it, then it's a bonus. 

The only problem I have with ACS is the same as my original problem.  I can't figure out if it is possible to play an audio file in reverse and change the rate of play for an audio file.  I have looked at the documentation, the source, performed Google searches, etc. 

If anyone could let me know if this is possible or not, I would really appreciate it.

Thanks,

David.

molly

  • Hero Member
  • *****
  • Posts: 2330
molly: I would like to have it play in reverse.  It makes it easier for a transcriber to know how far to back the recording up if they miss something.
Ok, in that case this is afaik not possible to do with MCI (But someone please proof me wrong on that, i simply was unable to figure it out on my own which doesn't include reversing the wav samples manually).

Other than that, i truly wonder if someone is able to recognize speech playing backwards.

Fred vS

  • Hero Member
  • *****
  • Posts: 3158
    • StrumPract is the musicians best friend
Quote
  I can't figure out if it is possible to play an audio file in reverse

The "SimplePlayer" demo of uos has a "Play Reverse" code.

Code: Pascal  [Select][+][-]
  1. ///// example how to do custom dsp
  2.  
  3.   function DSPReverseBefore(Data: TuosF_Data; fft: TuosF_FFT): TDArFloat;
  4.   begin
  5.     if Data.position > Data.OutFrames div Data.ratio then
  6.       uos_Seek(PlayerIndex1, InputIndex1, Data.position - 2 - (Data.OutFrames div Data.Ratio));
  7.   end;
  8.  
  9.   function DSPReverseAfter(Data: TuosF_Data; fft: TuosF_FFT): TDArFloat;
  10.   var
  11.     x: integer = 0;
  12.     arfl: TDArFloat;
  13.  
  14.   begin
  15.     SetLength(arfl, length(Data.Buffer));
  16.        while x < length(Data.Buffer)  do
  17.           begin
  18.       arfl[x] := Data.Buffer[length(Data.Buffer) - x - 1] ;
  19.       arfl[x+1] := Data.Buffer[length(Data.Buffer) - x ]  ;
  20.          x := x +2;
  21.           end;
  22.  
  23.     Result := arfl;
  24.   end;
Fre;D
« Last Edit: November 07, 2016, 08:23:33 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

dmudie

  • New member
  • *
  • Posts: 9
Thanks again for everyone's help

Molly: the playing backwards isn't so the user can understand the voice in reverse; it's so the user can listen for the gaps in the speech.  If s/he misses a word, s/he can listen until a gap is hit and stop there.  That will be the beginning of the word that was missed.  The same is true for phrases, etc.  In fact, the "old" transcription machines that used tape had this feature.

Fred vS: Thanks for the sample code.

 

TinyPortal © 2005-2018