This file contains hidden or 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
| const thread = spawn(function (input, done) { | |
| // get all code from localpackage | |
| const { calculateWavSpectrum } = require('fft-thread-worker'); | |
| calculateWavSpectrum(input.filePath, done); | |
| ... | |
| }) | |
| ... |
This file contains hidden or 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
| const spawn = require('threads').spawn; | |
| const { decode } = require('./src/utils/decoder'); | |
| const { fft, spliceSpectrum } = require('./src/utils/fft'); | |
| const decodeFiles = async (inFolder, outFolder) => { | |
| // 1 read all file inside of in folder | |
| const files = await getFilesInFolder(inFolder); | |
| for (let i = 0; i < files.length; i++) { | |
| const thread = spawn(function (input, done) { |
This file contains hidden or 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
| const decodeFiles = async (inFolder, outFolder) => { | |
| // 1 read all file inside of in folder | |
| const files = await getFilesInFolder(inFolder); | |
| for(let i=0; i < files.length; i++) { | |
| // 2 decode .wav to float array and get spectrum by fff | |
| decode(files[i].filePath).then(audioData => { | |
| const { spectrum } = fft(audioData.channelData[0]); | |
| const { splicedSpectrum } = spliceSpectrum(spectrum); | |
| // 3 write result ito out folder |
This file contains hidden or 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
| const config = { | |
| rate: 44100, | |
| channels: 2, | |
| device: `plughw:${process.argv[2] || 0}`, | |
| fileType: 'wav', | |
| }; | |
| const micInstance = mic(config); | |
| const stream = micInstance.getAudioStream(); |
This file contains hidden or 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
| import { Tracks } from '../../db'; | |
| export const createTrack = (_, { input }) => | |
| Tracks.create({ | |
| ...input, | |
| hypeCoefficient: 0, | |
| rating: 0, | |
| }); |
This file contains hidden or 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
| # In root.graphql | |
| type Mutation { | |
| createTrack(input: TrackInput!): Track | |
| } | |
| # In records.graphql | |
| input TrackInput { | |
| name: String! | |
| genres: [Genre]! | |
| releasedAt: Date! |
This file contains hidden or 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
| // In app.js add context option to express middleware | |
| graphqlExpress({ schema, context: { ...createLoaders() } }), | |
| // Access dataloaders from context in resolvers | |
| export const Album = { | |
| tracks: ({ tracks }, args, { tracksLoader }) => tracksLoader.loadMany(tracks), | |
| titleTrack: ({ titleTrack }, args, { tracksLoader }) => tracksLoader.load(titleTrack), | |
| artist: ({ artist }, args, { artistsLoader }) => artistsLoader.load(artist), | |
| }; |
This file contains hidden or 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
| import DataLoader from 'dataloader'; | |
| import { Artists, Tracks } from '../../db'; | |
| // Use toString to compare MongoID objects | |
| const idsEq = k => d => d._id.toString() === k.toString(); | |
| // Make sure that the docs are in the same order as keys and have null value if nothing found | |
| const mapLoaderRes = keys => data => | |
| keys.map(k => data.find(idsEq(k)) || null); |
This file contains hidden or 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
| export const ArtistType = { | |
| __resolveType: ({ type }) => { | |
| if (type === 'SINGLE') return 'Single'; | |
| if (type === 'BAND') return 'Band'; | |
| if (type === 'BAND_PARTICIPANT') return 'BandParticipant'; | |
| return null; | |
| }, | |
| }; | |
| export const BandParticipant = { |
This file contains hidden or 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
| export const Artist = { | |
| tracks: ({ _id }, args) => Tracks.find(...tracksQuery({ ...args, artists: [_id] })), | |
| albums: ({ _id }) => Albums.find({ artist: _id }), | |
| artistType: ({ artistType, _id }) => ({ ...artistType, _id }), | |
| }; |