1 //
2 // Copyright (c) 2010-2020 Antmicro
3 //
4 // This file is licensed under the MIT License.
5 // Full license text is available in 'licenses/MIT.txt'.
6 //
7 
8 using System;
9 
10 using Antmicro.Renode.Core;
11 using Antmicro.Renode.Sound;
12 using Antmicro.Renode.Logging;
13 
14 namespace Antmicro.Renode.Peripherals.Sound
15 {
16     public class LiteX_I2S_Master : LiteX_I2S, IDisposable
17     {
LiteX_I2S_Master(IMachine machine, DataFormat format, uint sampleWidthBits, uint samplingRateHz, uint numberOfChannels)18         public LiteX_I2S_Master(IMachine machine, DataFormat format, uint sampleWidthBits, uint samplingRateHz, uint numberOfChannels) : base(machine, format, sampleWidthBits, samplingRateHz)
19         {
20             encoder = new PCMEncoder(sampleWidthBits, samplingRateHz, numberOfChannels, false);
21         }
22 
ForceFlush()23         public void ForceFlush()
24         {
25             encoder.FlushBuffer();
26         }
27 
Dispose()28         public void Dispose()
29         {
30             encoder.Dispose();
31         }
32 
SetBuffering(uint ms)33         public void SetBuffering(uint ms)
34         {
35             encoder.SetBufferingByTime(ms);
36         }
37 
38         public string Output
39         {
40             get => encoder.Output;
41 
42             set
43             {
44                 encoder.Output = value;
45             }
46         }
47 
IsReady()48         protected override bool IsReady()
49         {
50             return (buffer.Count < fifoIrqThreshold);
51         }
52 
EnqueueSampleInner(uint sample)53         protected override void EnqueueSampleInner(uint sample)
54         {
55             encoder.AcceptSample(sample);
56             this.Log(LogLevel.Noisy, "Encoded a sample");
57         }
58 
59         private readonly PCMEncoder encoder;
60     }
61 }
62