Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
sigrdrifa committed Dec 26, 2023
1 parent 424230e commit be5eb90
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 7 deletions.
2 changes: 2 additions & 0 deletions audiocate.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ test-suite audiocate-test
EncodeSpec
, EncodeCmdSpec
, EncodeStreamCmdSpec
, DecodeSpec
, DecodeCmdSpec
, DecodeStreamCmdSpec
, StegoSpec
, RealTimeSpec
Expand Down
2 changes: 1 addition & 1 deletion lib/Audiocate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Command.Cmd (Command(..), CommandReturnCode(..), interpretCmd)

-- | Runs the provided Command
run :: Command -> Bool -> IO CommandReturnCode
run cmd isRealTime = interpretCmd cmd isRealTime
run = interpretCmd

-- | Prints the version string
version :: String
Expand Down
14 changes: 9 additions & 5 deletions lib/Command/EncodeCmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import Stego.Encode.Encoder
, stopEncoder
)

runEncodeCmd :: StegoParams -> FilePath -> FilePath -> IO (Either String DC.DecoderResultList)
runEncodeCmd ::
StegoParams
-> FilePath
-> FilePath
-> IO (Either String DC.DecoderResultList)
runEncodeCmd stegoParams inputFile outputFile = do
startTime <- getCurrentTime
audio <- runExceptT (waveAudioFromFile inputFile)
Expand Down Expand Up @@ -56,7 +60,7 @@ runEncodeCmd stegoParams inputFile outputFile = do
}
write <- runExceptT (waveAudioToFile outputFile wa')
case write of
Left err -> pure (Left err)
Left err -> pure (Left err)
Right _ -> do
endTime <- getCurrentTime
putStrLn $
Expand All @@ -71,13 +75,13 @@ doEncodeFrames stegoParams frames = do
decoder <- DC.newDecoder stegoParams
void $ DC.mapDecoderOpQToResultChan decoder resC
resD <- DC.getResultChannel decoder
x <- newEmptyTMVarIO
void $ forkIO $ decoderResultLoop resD [] (length frames) x
decoderStoppedTMVar <- newEmptyTMVarIO
void $ forkIO $ decoderResultLoop resD [] (length frames) decoderStoppedTMVar
void $ forkIO $ printLoop printChan (0 :: Int) (length frames)
mapM_ (enqueueFrame encoder) frames
t <- stopEncoder encoder
void $ atomically $ takeTMVar t
atomically $ takeTMVar x
atomically $ takeTMVar decoderStoppedTMVar
where
decoderResultLoop resD fs total t = do
res <- atomically $ readTChan resD
Expand Down
2 changes: 1 addition & 1 deletion lib/Stego/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type DecodedPayload = (Word64, TotpPayload)

type DecodedFrame = (Int, [Int16], DecodedPayload)

-- | StegoParams instance used to capture parameters
-- | StegoParams ADT used to capture parameters
data StegoParams =
StegoParams Secret Word64 Word8 EncodingType Payload Bool
deriving (Show, Eq)
Expand Down
10 changes: 10 additions & 0 deletions test/DecodeCmdSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module DecodeCmdSpec where

import Test.Hspec (Spec, shouldBe, describe, context, it)

spec :: Spec
spec = do
describe "Tests decoding command functionality" $ do
context "when passing it an empty frames list" $
it "should return an empty decode result" $ do
1 `shouldBe` 1
20 changes: 20 additions & 0 deletions test/DecodeSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module DecodeSpec where
import Test.Hspec (Spec, shouldBe, describe, context, it)
import Data.Word (Word64)
import Stego.Common (StegoParams(StegoParams), EncodingType (LsbEncoding))
import Stego.Decode.Decoder (newDecoder)
import Command.DecodeCmd (doDecodeFramesWithDecoder)
import Data.Text.Encoding (encodeUtf8)
import qualified Data.Text as T

spec :: Spec
spec = do
describe "Tests decoding functionality" $ do
let secret = encodeUtf8 (T.pack "test-secret")
let timeValid :: Word64 = 5
let stegoParams = StegoParams secret timeValid 6 LsbEncoding 0 False
context "when passing it an empty frames list" $
it "should return an empty decode result" $ do
decoder <- newDecoder stegoParams
result <- doDecodeFramesWithDecoder decoder []
result `shouldBe` []
Binary file added test/corpus/sample10.wav
Binary file not shown.
Binary file added test/corpus/sample11.wav
Binary file not shown.
Binary file added test/corpus/sample12.mp3
Binary file not shown.
Binary file added test/corpus/sample13.mp3
Binary file not shown.
Binary file added test/corpus/sample14.mp3
Binary file not shown.
Binary file added test/corpus/sample7.wav
Binary file not shown.
Binary file added test/corpus/sample8.wav
Binary file not shown.
Binary file added test/corpus/sample9.wav
Binary file not shown.
13 changes: 13 additions & 0 deletions test/output/bench_results.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Name,Mean (ps),2*Stdev (ps),Allocated,Copied,Peak Memory
All.EncodeStreamCmd.encodestream sample1,14693248093,320244484,93844548,6242,39845888
All.EncodeStreamCmd.encodestream sample2,155362127100,4587386028,1031954594,39988,39845888
All.EncodeStreamCmd.encodestream sample3,23896164562,2167280936,152509931,8260,39845888
All.EncodeStreamCmd.encodestream sample4,5668660943,504739462,35157292,2674,39845888
All.EncodeStreamCmd.encodestream sample5,62174701050,1524675918,404103044,17351,39845888
All.EncodeStreamCmd.encodestream sample6,799511155200,5021119264,5394626590,180326,39845888
All.DecodeStreamCmd.decodestream sample1,326157131,21820356,1628148,43,78643200
All.DecodeStreamCmd.decodestream sample2,3751838025,261938256,17227862,516,78643200
All.DecodeStreamCmd.decodestream sample3,556790365,51731942,2522569,80,78643200
All.DecodeStreamCmd.decodestream sample4,154461238,13456478,614678,17,78643200
All.DecodeStreamCmd.decodestream sample5,1459033971,142797040,6827953,176,78643200
All.DecodeStreamCmd.decodestream sample6,19889054037,951704294,92597287,2205,78643200
115 changes: 115 additions & 0 deletions test/output/bench_results.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit be5eb90

Please sign in to comment.