Jump to content

Undesirable pause when playing audio


Recommended Posts

Dear developers are faced with the problem of who is trying to resolve already probably a few weeks. I decided to address you as a specialist.

The challenge is to program to lose two parts audio record split in half. As much as I tried to do it and whatever function is not used, there is always a delay and audible pause at the beginning of the launch of the second part.

Note also that the weaker processor and the larger the file size, the more pause.

How can I play the two parts together so that there is no audible pause and transition? It is necessary to implement it.

 

#include <Sound.au3>

Dim $SFile1 = _SoundOpen("1-1.mp3")
Dim $SFile2 = _SoundOpen("1-2.mp3")

_SoundPlay($SFile1,1)
_SoundPlay($SFile2,1)

Please help me solve it. Thank you!

1.mp3

1-1.mp3

1-2.mp3

Link to comment
Share on other sites

Thank you for your attention and participation!
Such a decision, I also tried to apply. Clicks on the transition. In addition, the pause on different computers will be different. You have perfect sound with a value of 100. And I heard a click.
We need the best and universal solution.

Link to comment
Share on other sites

 

_Soundplay is very basic, you're asking too much from it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

@AndreyS,

Have you tried concatenating the files before playing?  I downloaded the 2 files and from a DOS prompt ran

copy /b 1-1.mp3 + 1-2.mp3 final.mp3

and played final.mp3 through my PC with no perceptible skip glitch or pause between the 2 9 second tracks.  You should be able to script that pretty easily.

 

Try this...

#include <Sound.au3>

Dim $SFile1 = "1-1.mp3"
Dim $SFile2 = "1-2.mp3"

RunWait(@ComSpec & " /c copy /b " & $Sfile1 & " + " & $SFile2 & " final.mp3")

$Final = _SoundOpen("final.mp3")
_SoundPlay($Final,1)

 

Edited by MuffinMan
added code
Link to comment
Share on other sites

They can not connect. They are specifically and broke up at the beginning. This is just an example. There will be a lot of pieces that will be played in a very different order. Besides, I did not want to have a hard disk and CPU load such file operations. 
Thank you, MuffinMan, for your participation!

 

Wow! This is something very powerful too! Thank you, BrewManNH, for your participation and the link!
I tried to implement my problem with this UDF.
Maybe I did something wrong, but I still audible clicking. Tell me, please, how to better implement it.

#include <Bass.au3>
#include <BassConstants.au3>

Global $playing_state = -1
;Open Bass.DLL.  Required for all function calls.
_BASS_STARTUP ("BASS.dll")

;Initalize bass.  Required for most functions.
_BASS_Init(0, -1, 44100, 0, "")

;Check if bass iniated.  If not, we cannot continue.
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf

;Prompt the user to select a MP3 file
$file1 = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")
$file2 = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")

;Create a stream from that file.
$MusicHandle1 = _BASS_StreamCreateFile(False, $file1, 0, 0, 0)
$MusicHandle2 = _BASS_StreamCreateFile(False, $file2, 0, 0, 0)

;Iniate playback
_BASS_ChannelPlay($MusicHandle1, 1)
$song_length = _BASS_ChannelGetLength($MusicHandle1, $BASS_POS_BYTE)
While _BASS_ChannelGetPosition($MusicHandle1, $BASS_POS_BYTE)<>$song_length
WEnd

_BASS_ChannelPlay($MusicHandle2, 1)
$song_length = _BASS_ChannelGetLength($MusicHandle2, $BASS_POS_BYTE)
While _BASS_ChannelGetPosition($MusicHandle2, $BASS_POS_BYTE)<>$song_length
WEnd


Func OnAutoItExit()
    ;Free Resources
    _BASS_Free()
EndFunc   ;==>OnAutoItExit

 

Edited by AndreyS
Link to comment
Share on other sites

Hi. You can do something like this.

#include <Bass.au3>
#include <BassConstants.au3>
#include <WinAPI.au3>
Global $playing_state = -1
;Open Bass.DLL.  Required for all function calls.
_BASS_STARTUP("BASS.dll")

;Initalize bass.  Required for most functions.
_BASS_Init(0, -1, 44100, 0, "")

;Check if bass iniated.  If not, we cannot continue.
If @error Then
    MsgBox(0, "Error", "Could not initialize audio")
    Exit
EndIf

;Prompt the user to select a MP3 file
$sFilePath1 = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")
$sFilePath2 = FileOpenDialog("Open...", "", "MP3 Files (*.mp3)")


Local $iFileSize1 = FileGetSize($sFilePath1)
Local $iFileSize2 = FileGetSize($sFilePath2)

If $iFileSize1 and $iFileSize2 Then

    Local $tBuffer = DllStructCreate("byte StreamFile1[" & $iFileSize1 & "];byte StreamFile2[" & $iFileSize2 & "]")
    Local $pMemory=DllStructGetPtr($tBuffer)
    $tBuffer.StreamFile1=FileRead($sFilePath1)
    $tBuffer.StreamFile2=FileRead($sFilePath2)

    Local $hMusic = _BASS_StreamCreateFile(True, $pMemory, 0, $iFileSize1 + $iFileSize2, 0)
    Local $song_length = _BASS_ChannelGetLength($hMusic, $BASS_POS_BYTE)
    _BASS_ChannelPlay($hMusic, 1)
    While True
        If _BASS_ChannelGetPosition($hMusic, $BASS_POS_BYTE) = $song_length Then ExitLoop
    WEnd

EndIf

Func OnAutoItExit()
    ;Free Resources
    _BASS_Free()
EndFunc   ;==>OnAutoItExit

Saludos

Link to comment
Share on other sites

Yes, sounds are now together! Thank you! There is hope now! :)

And you can still somehow simplify the code? You can use only the function of Bass.au3?

And at the end of play audible sounds precipitous ending of the second file 4 times for about 200 ms. Because of what these overtones?

Link to comment
Share on other sites

simplify ? It's simple...

I dont understand your point aobut ending...

Saludos

Link to comment
Share on other sites

mmm rare. I tested over Windows 10 and windows 7. I dont have overtones in the end.

 

Saludos

Link to comment
Share on other sites

mmm I don't think.

When you open 1-1.mp3 and 1-2.mp3 what is your channel length? I got 3105792?

 

Saludos

Link to comment
Share on other sites

Link to comment
Share on other sites

Simply add sleep in while.

 

While True
        If _BASS_ChannelGetPosition($hMusic, $BASS_POS_BYTE) = $song_length Then ExitLoop
        Sleep(100)
    WEnd

Saludos

Link to comment
Share on other sites

I understood why the processor so loaded. Because of cycle. It is, in principle, no problem. But for some reason the script does not complete its work at the end? Can not understand.
 

Yes, yes definitely need a sleep()

Edited by AndreyS
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...