re-implement format conversion with pycsdr
This commit is contained in:
		@@ -1,5 +1,9 @@
 | 
				
			|||||||
from abc import ABCMeta
 | 
					from abc import ABCMeta
 | 
				
			||||||
from owrx.source import SdrSource, SdrDeviceDescription
 | 
					from owrx.source import SdrSource, SdrDeviceDescription
 | 
				
			||||||
 | 
					from csdr.chain import Chain
 | 
				
			||||||
 | 
					from typing import Optional
 | 
				
			||||||
 | 
					from pycsdr.modules import Buffer
 | 
				
			||||||
 | 
					from pycsdr.types import Format
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -38,16 +42,30 @@ class DirectSource(SdrSource, metaclass=ABCMeta):
 | 
				
			|||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getCommand(self):
 | 
					    def getCommand(self):
 | 
				
			||||||
        return super().getCommand() + self.getFormatConversion() + self.getNmuxCommand()
 | 
					        return super().getCommand() + self.getNmuxCommand()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # override this in subclasses, if necessary
 | 
					    # override this in subclasses, if necessary
 | 
				
			||||||
    def getFormatConversion(self):
 | 
					    def getFormatConversion(self) -> Optional[Chain]:
 | 
				
			||||||
        return []
 | 
					        return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # override this in subclasses, if necessary
 | 
					    # override this in subclasses, if necessary
 | 
				
			||||||
    def sleepOnRestart(self):
 | 
					    def sleepOnRestart(self):
 | 
				
			||||||
        pass
 | 
					        pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def getBuffer(self):
 | 
				
			||||||
 | 
					        if self.buffer is None:
 | 
				
			||||||
 | 
					            source = self._getTcpSource()
 | 
				
			||||||
 | 
					            buffer = Buffer(source.getOutputFormat())
 | 
				
			||||||
 | 
					            source.setWriter(buffer)
 | 
				
			||||||
 | 
					            conversion = self.getFormatConversion()
 | 
				
			||||||
 | 
					            if conversion is not None:
 | 
				
			||||||
 | 
					                conversion.setReader(buffer.getReader())
 | 
				
			||||||
 | 
					                # this one must be COMPLEX_FLOAT
 | 
				
			||||||
 | 
					                buffer = Buffer(Format.COMPLEX_FLOAT)
 | 
				
			||||||
 | 
					                conversion.setWriter(buffer)
 | 
				
			||||||
 | 
					            self.buffer = buffer
 | 
				
			||||||
 | 
					        return self.buffer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DirectSourceDeviceDescription(SdrDeviceDescription):
 | 
					class DirectSourceDeviceDescription(SdrDeviceDescription):
 | 
				
			||||||
    pass
 | 
					    pass
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,9 @@
 | 
				
			|||||||
from owrx.command import Option
 | 
					from owrx.command import Option
 | 
				
			||||||
from owrx.source.direct import DirectSource, DirectSourceDeviceDescription
 | 
					from owrx.source.direct import DirectSource, DirectSourceDeviceDescription
 | 
				
			||||||
from subprocess import Popen
 | 
					from subprocess import Popen
 | 
				
			||||||
 | 
					from csdr.chain import Chain
 | 
				
			||||||
 | 
					from pycsdr.modules import Convert, Gain
 | 
				
			||||||
 | 
					from pycsdr.types import Format
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,8 +23,8 @@ class FifiSdrSource(DirectSource):
 | 
				
			|||||||
    def getEventNames(self):
 | 
					    def getEventNames(self):
 | 
				
			||||||
        return super().getEventNames() + ["device"]
 | 
					        return super().getEventNames() + ["device"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getFormatConversion(self):
 | 
					    def getFormatConversion(self) -> Chain:
 | 
				
			||||||
        return ["csdr convert_s16_f", "csdr gain_ff 5"]
 | 
					        return Chain([Convert(Format.COMPLEX_SHORT, Format.COMPLEX_FLOAT), Gain(Format.COMPLEX_FLOAT, 5.0)])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def sendRockProgFrequency(self, frequency):
 | 
					    def sendRockProgFrequency(self, frequency):
 | 
				
			||||||
        process = Popen(["rockprog", "--vco", "-w", "--freq={}".format(frequency / 1e6)])
 | 
					        process = Popen(["rockprog", "--vco", "-w", "--freq={}".format(frequency / 1e6)])
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user