@@ -22,6 +22,7 @@ public class AudioClipWidget : UnityObjectWidget
22
22
static AudioSource Source ;
23
23
static AudioClipWidget CurrentlyPlaying ;
24
24
static Coroutine CurrentlyPlayingCoroutine ;
25
+ static readonly string zeroLengthString = GetLengthString ( 0f ) ;
25
26
26
27
public AudioClip RefAudioClip ;
27
28
private string fullLengthText ;
@@ -112,7 +113,6 @@ static string GetLengthString(float seconds)
112
113
sb . Append ( $ "{ ts . Hours } :") ;
113
114
114
115
sb . Append ( $ "{ ts . Minutes : 00} :") ;
115
-
116
116
sb . Append ( $ "{ ts . Seconds : 00} :") ;
117
117
sb . Append ( $ "{ ts . Milliseconds : 000} ") ;
118
118
@@ -121,7 +121,7 @@ static string GetLengthString(float seconds)
121
121
122
122
private void ResetProgressLabel ( )
123
123
{
124
- this . progressLabel . text = $ "{ GetLengthString ( 0f ) } / { fullLengthText } ";
124
+ this . progressLabel . text = $ "{ zeroLengthString } / { fullLengthText } ";
125
125
}
126
126
127
127
private void OnPlayStopClicked ( )
@@ -152,8 +152,7 @@ static void SetupAudioPlayer()
152
152
AudioPlayerObject = new GameObject ( "UnityExplorer.AudioPlayer" ) ;
153
153
UnityEngine . Object . DontDestroyOnLoad ( AudioPlayerObject ) ;
154
154
AudioPlayerObject . hideFlags = HideFlags . HideAndDontSave ;
155
- AudioPlayerObject . transform . position = new ( int . MinValue , int . MinValue ) ;
156
-
155
+ AudioPlayerObject . transform . position = new ( int . MinValue , int . MinValue ) ; // move it as far away as possible
157
156
#if CPP
158
157
Source = AudioPlayerObject . AddComponent ( UnhollowerRuntimeLib . Il2CppType . Of < AudioSource > ( ) ) . TryCast < AudioSource > ( ) ;
159
158
#else
@@ -305,6 +304,7 @@ public override GameObject CreateContent(GameObject uiRoot)
305
304
public static class SavWav
306
305
{
307
306
public const int HEADER_SIZE = 44 ;
307
+ public const float RESCALE_FACTOR = 32767 ; // to convert float to Int16
308
308
309
309
public static void Save ( AudioClip clip , string filepath )
310
310
{
@@ -335,17 +335,17 @@ static void ConvertAndWrite(FileStream fileStream, AudioClip clip)
335
335
clip . GetData ( samples , 0 ) ;
336
336
#endif
337
337
338
+ int len = samples . Length ;
339
+
338
340
// converting in 2 float[] steps to Int16[], then Int16[] to Byte[]
339
- short [ ] intData = new short [ samples . Length ] ;
341
+ short [ ] intData = new short [ len ] ;
340
342
341
343
// bytesData array is twice the size of dataSource array because a float converted in Int16 is 2 bytes.
342
- byte [ ] bytesData = new byte [ samples . Length * 2 ] ;
343
-
344
- float rescaleFactor = 32767 ; // to convert float to Int16
344
+ byte [ ] bytesData = new byte [ len * 2 ] ;
345
345
346
- for ( int i = 0 ; i < samples . Length ; i ++ )
346
+ for ( int i = 0 ; i < len ; i ++ )
347
347
{
348
- intData [ i ] = ( short ) ( samples [ i ] * rescaleFactor ) ;
348
+ intData [ i ] = ( short ) ( samples [ i ] * RESCALE_FACTOR ) ;
349
349
byte [ ] byteArr = BitConverter . GetBytes ( intData [ i ] ) ;
350
350
byteArr . CopyTo ( bytesData , i * 2 ) ;
351
351
}
0 commit comments