-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Refactored LoopingSampleProvider - Started stubbing the MediaCacheManager - Added new waveform renderer view model - Added peak file reader/writer (it's REALLY fast!) - Added new waveform control - Updated views to support the waveform control - Added waveform popup window to appreciate the pretty waveforms up close ;-) - Other small changes
- Loading branch information
Showing
12 changed files
with
1,036 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using NAudio.Wave; | ||
using System; | ||
|
||
namespace QPlayer.ViewModels | ||
{ | ||
public class LoopingSampleProvider<T> : WaveStream, ISampleProvider where T : WaveStream, ISampleProvider | ||
{ | ||
private readonly T input; | ||
private readonly bool infinite; | ||
private readonly int loops; | ||
private long playedLoops = 0; | ||
|
||
public LoopingSampleProvider(T input, bool infinite = true, int loops = 1) | ||
{ | ||
this.input = input; | ||
this.infinite = infinite; | ||
this.loops = loops; | ||
} | ||
|
||
public override WaveFormat WaveFormat => input.WaveFormat; | ||
|
||
public override long Length => infinite ? long.MaxValue/32 : input.Length * loops; | ||
|
||
public override long Position | ||
{ | ||
get => input.Position; | ||
set | ||
{ | ||
input.Position = value % input.Length; | ||
playedLoops = value / input.Length; | ||
} | ||
} | ||
|
||
public int Read(float[] buffer, int offset, int count) | ||
{ | ||
int samplesRead = 0; | ||
int readOffset = offset; | ||
while (samplesRead < count) | ||
{ | ||
int read = input.Read(buffer, readOffset, count - samplesRead); | ||
readOffset += read; | ||
if (read == 0) | ||
{ | ||
input.Position = 0; | ||
readOffset = 0; | ||
playedLoops++; | ||
|
||
if (!infinite && playedLoops == loops) | ||
break; | ||
} | ||
} | ||
return samplesRead; | ||
} | ||
|
||
public override int Read(byte[] buffer, int offset, int count) | ||
{ | ||
int samplesRead = 0; | ||
int readOffset = offset; | ||
while (samplesRead < count) | ||
{ | ||
int read = input.Read(buffer, readOffset, count - samplesRead); | ||
readOffset += read; | ||
if (read == 0) | ||
{ | ||
input.Position = 0; | ||
readOffset = 0; | ||
playedLoops++; | ||
|
||
if (!infinite && playedLoops == loops) | ||
break; | ||
} | ||
} | ||
return samplesRead; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace QPlayer.ViewModels | ||
{ | ||
internal class MediaCacheManager | ||
{ | ||
private ConcurrentDictionary<string, CachedMediaStream> cacheDict; | ||
|
||
public MediaCacheManager() | ||
{ | ||
cacheDict = new(); | ||
} | ||
} | ||
|
||
internal class CachedMediaStream : MemoryStream, IDisposable | ||
{ | ||
protected int references = 0; | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
} | ||
|
||
void IDisposable.Dispose() | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.