I got hired as an iOS developer for a startup!

I haven’t been updating my blog because I got hooked developing a podcast player (which Im still developing). When I started learning iOS it was never my intention to become a developer for a startup, but I started getting more boring responsibilities at my current engineering job and I needed to focus more of my attention on growing/taking risks on myself instead of checking spreadsheets. So I saw this position for a Jr. mobile developer on indeed.com and I got an interview the next day and hired on the spot. I saw great potential to grow with the startup, more potential to impact people’s lives and learn more about iOS. 

I took a pay cut because I believe on what they do and the team looks happy to be there. I know whatever I learn and apply myself it will help me for the challenging future. I know I will have to work way more than my current RF position, but I know it will be worth it. I don’t know if in the future I want to have a startup, a small business, or be a freelancer, but I do know I want to be somebody and I’m willing to take the risk.

Now I do think what helped me to get the job was my soft skills and to be likable i.e.: Smiling, be excited, asking questions, looking sharp, be in shape, current projects and have an app in the App Store to show(source code included). As well they saw that I was single with no responsibilities and they needed someone hungry willing to grind/learn. So I’m moving to downtown and my job will be within walking distance. I really HATE commuting, is the most soul crushing thing and not to mention you share the road with neurotic/crazy human beings.

So sometimes you have to take the opportunities that are in front in you and give your best. I learned to stop thinking about how the future should look like, because it will never be like you imagined and enjoy the moment.  

Last minute Post

It’s almost June and I almost forgot to write a post this month, times goes by so fast. Anyway I been having a great time here in Addison making some coins and paying debts which next month I will be debt free forever, debt kills dreams…sigh. Also I look more muscular since I have more opportunity to lift and sleep a bit more by only going to the gym 3x a week for 1hr.

I love having flexibility on my job, but I really want to work from home everyday. I don’t mind working all day as long i don’t have to commute to an office full of bright incandescent lights. Currently I work from home 2 days and its a blast to waking up to not having to rush and fight traffic half asleep. Waking up to the smell of coffee and the sound of birds or minimal music in my quiet studio apartment.The dream….  Maybe it will get old? I don’t know but I love it and I will fight for this kind of lifestyle.

On programming I been trying different ideas. One is to make a podcast app with a new feature and another is to make apps for radio stations. I wrote a sales letter to a radio station for a great looking app and see if they respond. I read books like No B.S. by Dan Kennedy and I really like its No B.S. teaching style about copywriting. Another book is Unscripted by MJ Demarco and its about how society condition us to be consumers. Also I tried to validate my idea of the podcast app by using google Adwords, Facebook ads and I can see that there’s “so so” demand, maybe my copywriting was not strong enough. I will build it and see what happens. I want to be great!

I been thinking that I want to focus more and learn how to actually learn how to spot needs/problems and then build the app for it. I don’t want to build for nobody, I don’t care what other programmers say like “build stuff you love”, see I love that people find useful what I have to offer and be able to eat well everyday. So I will need to learn more about marketing and try more “salesy” stuff.

WWDC is next week! Ready to break everything out there with Swift 4, but I’m excited to see what’s new.

Time to work!

New location

Finally, I moved to Addison, TX and so far everything is going great with my job. The food in the cafeteria is delicious and cheap, I don’t have to pay $125 for parking, the gym is not a franchise(crowded) and traffic is not bad at all! My work seems to have a lot of flexibility, so that will give me a great opportunity to get in great shape and save a lot of money. I feel more happy and energetic, I felt I was dying inside at my job in Fort Worth. I feel I can learn more rewarding things at this new job which is RF stuff, I always wanted to learn all these antennas stuff.

At the same time, I almost lost my momentum programming audio, since I didn’t program in 4 days while I was moving to Addison. It’ amazing how quick can you lose something that it took you a lot of time to build such as good habits, but it feels good to be back on the grind. Currently I’m trying to build an audio editor app and I learned that simple things take so much time to build or maybe I’m a slow programmer.

I shouldn’t be so hard on myself because I still need to get used to this new environment, but at the same time I can’t rest on my laurels. What matters is always to strive for a better life and say no to a lot distractions. The only thing I really struggle to stop doing is going out with friends and socialize on Saturday night since it gets very lonely at programming, just you and your computer painting pixels on the screen. It can feel that everything you’re doing is a waste of time and some dude in China who has no life already did it better and for free, but I have to trust the process.

Things…. take time! MASSIVE Action and MASSIVE Patience.

On another note, something that I’m trying to improve consistently is my people skills. Sometimes I can be very introverted person, but when I’m happy I’m very extroverted. It’s a weird dynamic that I must become an expert in, people skills are everything. Specially that English is my second language, I want to be able to articulate better sentences, to say things quickly and to kill my inner shyness.

How to create a volume meter in Swift 3

We’re going to create this easy volume meter with AVFoundation and a progress view

You can also add this to incoming audio(microphone), add audio effects, etc… but for now a player will do the job.

-First we start by adding a Progress view to the storyboard

Screen Shot 2017-03-18 at 3.05.36 PM.png

 

-Create an outlet in the Viewcontroller of the progress view and name it volumeMeter.

-Import AVFoundation

import AVFoundation

 

-include an audio File to your project navigator, you can use mine if you want

Click save link as…

-add these properties on the class  ViewController

    var engine: AVAudioEngine!      //The Audio Engine
    var player: AVAudioPlayerNode!  //The Player of the audiofile
    var file = AVAudioFile()        //Where we're going to store the audio file
    var timer: Timer?               //Timer to update the meter every 0.1 ms
    var volumeFloat:Float = 0.0     //Where We're going to store the volume float

 

-On the ViewDidLoad() add this code that will Initialize the engine and load the .m4a audio into an audiofile.

Note: replace the parameter strings for your audio file name “forResource” and “ofTYpe”.

        //init engine and player
        engine = AVAudioEngine()
        player = AVAudioPlayerNode()

        //Look for the audiofile on the project
        let path = Bundle.main.path(forResource: "Electronic", ofType: "m4a")!
        let url = NSURL.fileURL(withPath: path)

        //create the AVAudioFile
        let file = try? AVAudioFile(forReading: url)
        let buffer = AVAudioPCMBuffer(pcmFormat: file!.processingFormat, frameCapacity: AVAudioFrameCount(file!.length))
        do {
            //Do it
            try file!.read(into: buffer)
        } catch _ {
        }

 

-Next we’re going to connect the player and the engine together

        engine.attach(player)
        engine.connect(player, to: engine.mainMixerNode, format: buffer.format)

 

-We’re going to installTap on the mainMixerNode to extract that juicy float


        //installTap with a bufferSize of 1024 with the processingFormat of the current audioFile on bus 0
        engine.mainMixerNode.installTap(onBus:0, bufferSize: 1024, format: file?.processingFormat) {
            (buffer : AVAudioPCMBuffer!, time : AVAudioTime!) in

            let dataptrptr = buffer.floatChannelData!           //Get buffer of floats
            let dataptr = dataptrptr.pointee
            let datum = dataptr[Int(buffer.frameLength) - 1]    //Get a single float to read

            //store the float on the variable
            self.volumeFloat = fabs((datum))

        }

 

-Next we’re going to start the engine and play file.


        //Loop the audio file for demo purposes
        player.scheduleBuffer(buffer, at: nil, options: AVAudioPlayerNodeBufferOptions.loops, completionHandler: nil)

        engine.prepare()
        do {
            try engine.start()
        } catch _ {
        }

        player.play()

 

-Create a timer to update the volumeMeter every 0.1 miliseconds

        //start timer to update the meter
        timer = Timer.scheduledTimer(timeInterval: 0.1 , target: self, selector: #selector(updateMeter), userInfo: nil, repeats: true)

 

-Finally we’re going to create a new function named updateMeter() that’s going to be called by the timer every 0.1 ms to update the progressView with the new float value.


     func updateMeter() {
        self.volumeMeter.setProgress(volumeFloat, animated: false)

        if volumeMeter.progress > 0.8{//turn red if the volume is LOUD
            volumeMeter.tintColor = UIColor.red

        }else{//else green
            volumeMeter.tintColor = UIColor.green
        }

    }

 

Conclusion:
This is not a perfect volume meter, but it’s a start for more advanced meters.

Github or die

volume meter 2

How to create a SoundCloud like waveform in Swift 3

 

The first thing you need to get is the array of floats from the audio file and we’re going to use AVFoundation for that.

import AVFoundation

create a struct outside the class to store the audio information.

struct ReadFile {
    static var arrayFloatValues:[Float] = []
    static var points:[CGFloat] = []

}

-Add the audio file you want to analyze to the project navigator
-Add this code in ViewDidLoad()
Note: Make sure to change the forResource and withExtension parameters.

override func viewDidLoad() {
        super.viewDidLoad()

        //Look for sample2.m4a audio file
        let url = Bundle.main.url(forResource: "sample2", withExtension: "m4a")
        let file = try! AVAudioFile(forReading: url!)//Read File into AVAudioFile
        let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: file.fileFormat.sampleRate, channels: file.fileFormat.channelCount, interleaved: false)//Format of the file

        let buf = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: UInt32(file.length))//Buffer
        try! file.read(into: buf)//Read Floats
        //Store the array of floats in the struct
         readFile.arrayFloatValues = Array(UnsafeBufferPointer(start: buf.floatChannelData?[0], count:Int(buf.frameLength)))

    }

-Create new swift file and name it DrawWaveform
-subclass UIView and import UIKit and Accelerate frameworks

import UIKit
import Accelerate

class DrawWaveform: UIView {

    //This is where we're going to draw the waveform
    override func draw(_ rect: CGRect) {

     }

}

But before drawing we need to downsample the array of floats, because we don’t need to draw ALL of the floats.
To do this we’re going to use Accelerate framework

-create a new function in the new swift file ‘convertToPoints()’

-Copy this code inside the function convertToPoints(). I will explain this code in detail in another post, but it just reduces the size of the array and converts it to CGFloat.


func convertToPoints() {
        var processingBuffer = [Float](repeating: 0.0,
                                       count: Int(readFile.arrayFloatValues.count))
        let sampleCount = vDSP_Length(readFile.arrayFloatValues.count)
        //print(sampleCount)
        vDSP_vabs(readFile.arrayFloatValues, 1, &processingBuffer, 1, sampleCount);
        // print(processingBuffer)

        //THIS IS OPTIONAL
        // convert do dB
        //    var zero:Float = 1;
        //    vDSP_vdbcon(floatArrPtr, 1, &zero, floatArrPtr, 1, sampleCount, 1);
        //    //print(floatArr)
        //
        //    // clip to [noiseFloor, 0]
        //    var noiseFloor:Float = -50.0
        //    var ceil:Float = 0.0
        //    vDSP_vclip(floatArrPtr, 1, &noiseFloor, &ceil,
        //                   floatArrPtr, 1, sampleCount);
        //print(floatArr)

        var multiplier = 1.0
        print(multiplier)
        if multiplier < 1{
            multiplier = 1.0

        }

        let samplesPerPixel = Int(150 * multiplier)
        let filter = [Float](repeating: 1.0 / Float(samplesPerPixel),
                             count: Int(samplesPerPixel))
        let downSampledLength = Int(readFile.arrayFloatValues.count / samplesPerPixel)
        var downSampledData = [Float](repeating:0.0,
                                      count:downSampledLength)
        vDSP_desamp(processingBuffer,
                    vDSP_Stride(samplesPerPixel),
                    filter, &downSampledData,
                    vDSP_Length(downSampledLength),
                    vDSP_Length(samplesPerPixel))

        // print(" DOWNSAMPLEDDATA: \(downSampledData.count)")

        //convert [Float] to [CGFloat] array
        readFile.points = downSampledData.map{CGFloat($0)}

    }

    

Now we’re going to draw the waveform with the downsampled array.
copy this code inside the draw function in the subview.

This uses UIBezierPath and loops thru the array of floats to draw and at the apply stroke to fill it with color!

Where x is the distance between squares and y is the amplitude of the square.

    override func draw(_ rect: CGRect) {

 //downsample and convert to [CGFloat]
        self.convertToPoints()

        var f = 0
        //the waveform on top
        let aPath = UIBezierPath()
        //the waveform on the bottom
        let aPath2 = UIBezierPath()

        //lineWidth
        aPath.lineWidth = 2.0
        aPath2.lineWidth = 2.0

        //start drawing at:
        aPath.move(to: CGPoint(x:0.0 , y:rect.height/2 ))
        aPath2.move(to: CGPoint(x:0.0 , y:rect.height ))

        //Loop the array
        for _ in readFile.points{
                //Distance between points
                var x:CGFloat = 2.5
                //next location to draw
                aPath.move(to: CGPoint(x:aPath.currentPoint.x + x , y:aPath.currentPoint.y ))

                //y is the amplitude of each square
                aPath.addLine(to: CGPoint(x:aPath.currentPoint.x  , y:aPath.currentPoint.y - (readFile.points[f] * 70) - 1.0))

                aPath.close()

                x += 1
                f += 1
        }

        //If you want to stroke it with a Orange color
        UIColor.orange.set()
        aPath.stroke()
        //If you want to fill it as well
        aPath.fill()

        f = 0
        aPath2.move(to: CGPoint(x:0.0 , y:rect.height/2 ))

        //Reflection of waveform
        for _ in readFile.points{
            var x:CGFloat = 2.5
            aPath2.move(to: CGPoint(x:aPath2.currentPoint.x + x , y:aPath2.currentPoint.y ))

            //y is the amplitude of each square
            aPath2.addLine(to: CGPoint(x:aPath2.currentPoint.x  , y:aPath2.currentPoint.y - ((-1.0 * readFile.points[f]) * 50)))

            // aPath.close()
            aPath2.close()

            //print(aPath.currentPoint.x)
            x += 1
            f += 1
        }

        //If you want to stroke it with a Orange color
        UIColor.orange.set()
        //Reflection and make it transparent
        aPath2.stroke(with: CGBlendMode.normal, alpha: 0.5)

        //If you want to fill it as well
        aPath2.fill()

}
 

Next step is go to the storyboard and create a UIVIEW and change the class to ‘DrawWaveform’

Build and Run.

Screen Shot 2017-03-13 at 8.38.38 PM

Here’s the Github Link

APPSTORE release and first sale!

Finally, my app ‘Loop maker’ it’s in the app store new and alive! It took me long time to build it since I got distracted with objective c and another framework that later was deprecated. It was a long process but I learned a lot from ux to low level core audio and dealing with the tedious appstore. I’m getting downloads but not in app purchases, maybe I should get better at marketing or make a bigger product. Anyway I feel great, proud, and energetic! I also I made my first sale, can I call myself an entrepreneur?

link for app:https://goo.gl/0kjbAzScreen Shot 2017-03-07 at 4.07.17 PM.png

I presented my app to app developers meetup group and met many developers, it was nice to network. I noticed that I suck at presenting my own projects so I should work on my public speaking skills and my English.

Change of plans now! Haha wow life doesn’t go as planned isn’t… I had to give my parents money and I got offered an interesting job for my next rotation “Radio access network engineer”. The reason I say it’s a good option it’s because I’m moving to an apartment that its 680/month instead of 1200/month which aligns to my goals of being an entrepreneur. I’m not going to have to pay $125 for parking and $30 for the gym which brings my cost of living way low. I also finished paying off my car loan(12k) and next it’s my student loan(4k). 

My studio apartment will look like an office and I can already see friends saying “this is where you live?”, but I don’t care. I don’t care about traveling. I don’t care about having a beer after work. I don’t care about watching Netflix. I don’t care about politics. I don’t care about Religion. I don’t care about kids. I don’t care about the news. I don’t care about mortgages. I don’t care about the new Nintendo. I care about changing my life and I’m willing to work for it.

I’m already thinking on my next app idea…

Birthday month

November 12 was 26th birthday  and remember that drum machine I was trying to build in the beginning of 2016? I’m almost done with all the processing. I committed myself to learn some parts of core audio and the amazing audio engine 2(deprecated). I hired a graphic designer in upwork to do the user interface for me, focus on your strengths right? I still need to create the waveform logic, sequencer UI, menu integration and load audio from sample kits.

Creating apps is a very laborious work and it takes as 10x time to build if you don’t know what it takes. Sometimes it feels that I am going too slow and I haven’t release an app in a year, but I have to be patient as Gary Vee says.

Machine Learning

Another very interesting area  that I had been looking into for some time is Machine learning with audio or music also called Music Information Retrieval. After I completed and marketed my app I will study more of this subject and try to build a useful app with it. Everyone is talking about how robots are learning, going to take over the world and I see some great innovations with machine learning.

Digital signal processing helps in identifying features of a song such as pitch, tempo, etc… I feel that in Audio digital signal processing all the problems are already solved, but with machine learning I see how can we improve audio or music apps to be more intelligent and expressive. My dream is to have a profitable audio app and become an expert on my subject. I will do whatever it takes to keep pursuing it!

Life

So as I’m writing this in the bus I had an interview yesterday to work from home in my next rotation with the current company I am. I honestly don’t care what kind of work I do as long I can optimize my life and save time working from home. My plan is to workout at lunch and live a more healthy life as I think going to a cubicle drains my energy.

April 1st is my next rotation to be uncomfortable again and meet new people that will push me to be better. An area that I’m lacking is going out on weekends, I just cant give up my social life, it’s a struggle to just be at home not meeting new people. Maybe going out isn’t the problem and drinking is since that takes a lot of my energy the next day. I need to solve that asap…

I’m obsessed with having a better life.

 

 

 

 

 

 

 

 

 

 

Climbing Core Audio

mordor.png

Core Audio

I encountered a huge roadblock to finish my toy app and that its ‘offline rendering’, I can’t do that with AVFoundation. So I had to revisit the book “Learning core audio” by Chris Adamson which I tried to read a while ago to only don’t understand anything. Now I was able to understand the book and create cool stuff such as reading Floats from an audio file and plot a waveform  happy. I think I’m barely starting to get momentum and that helps with learning concepts faster.

waveform

It’s very easily to get discouraged to know all the time/effort it takes to build something simple and see all the people that have done it already. The secret is to only focus on yourself and DO IT ANYWAY, you learn as you go. Another thing is that swift 3 is a new language and it adds excitement because something hasn’t been done in swift.

I code every day and try to go to bed knowing a little bit more about swift or audio. In my mind I keep telling that is like going to the gym/dieting, the more work you put in the more you get out. Even though I’m not a fitness enthusiast I’m an audio maniac!!!!!! I would love to just take a year off and do work every hour but I have loans to pay  .

Fulfillment

There’s a of strong feeling of fulfillment when I’m doing my own thing, a feeling that I felt every day when I was making music/DJing when I was a teenager. Today that feeling is there when I put in work and I make a code work, or learned something that I can apply. Maybe that’s the reason people say “it’s about the journey, not the destination”.  You have to like what you’re doing and willing to do it every god damn day (notice I didn’t say passion).

I have a lot of fuel to change my life for the better, even though going to college and getting a good job already has provided me with %100 better conditions of living and opportunities… I want MORE. I want to be able to an expert in my field and be able to help people.

You have to do it and do it and do it and do it and do it and do it and do it and do it until the job gets done.

First year

Life by design

Today it’s been a year since I started blogging about learning audio programming and I did learned a lot about audio. This year I learned a lot about distractions and the resistance to grow, I can say it was a very productive year with some mistakes of course. This year I absorbed all information I could about audio and it wasn’t easy because a lot of the stuff was way over my head, but some was easy to understand thanks to my previous experience as music producer and college education. Even though I feel that I barely scratched the surface about audio I should celebrate the small wins and never quit. I started by taking online classes on audio, DSP and programming in IOS.

Currently I’m making a ‘toy app’ which simply morphs your voice, but the first idea was to make that as an app extension for the imessage app until I discovered that I couldn’t use the microphone for extensions, so I had to change. Even though it’s a very simple app and there’s tons in the appstore like it, I just want to finish it and have something out there. The app it’s almost finished and I just need to do the tedious work of the app (variations of voice effects) and final details. I used swift 3.0 to program the app and it wasn’t very hard to make since it’s a high level language, but I learned a lot and hopefully someone will download it and like it, if I can make a couple bucks out of it I will consider that a success. I’m going to use search ads in the appstore to learn more about marketing (you pay to learn), and get instant feedback. “You can read all you want about swimming, but until you jump into the pool you will learn how to swim” that’s my motto for anything, we get stuck reading about everything and never making our own conclusions. TRY IT FOR YOURSELF AND MAKE YOUR OWN CONCLUSIONS!

Focus to finish

I need to focus more on one thing at a time, finish it and stick to it till completion or death. That’s something very important I learned as a music producer, I would start dozens of cool music loops but lost interest when expanding that loop into a full song. I learned that the completed songs stuck to me forever even if no one heard some of the songs, I felt proud and felt good. I don’t remember all the hundreds loops I did and I became so good at making badass loops but not badass songs, so the same thing we can say about building apps, or any other endeavor. Just finish it and get it out there!!!!

One of the biggest enemies of success is our own resistance to simply sit down and do work as perfectly stated in the book “war of art” a great book that I gave as a gift to my brother. One of my struggles are doing work in the weekends, I just can’t dedicate my weekend nights to work, when I want to be out and be social. During the weekdays I have no problem coming from work, microwave my already prepared chicken and focus on work on my side project until 10pm(sleep time), I guess it’s a great habit I built. On weekends it’s another story and its when I wash clothes, clean, meal prep, work out (frid,sat,sun) and I do some distracted work (by work I don’t mean my full time job) .

When I go out with friends I try to do it the “smart” way, by going out late 11pm-12pm and only if I know it’s going to be a fun night. I don’t go to the bar to just have a beer or hang out to have a beer or come home after work to have a beer and watch the game. Time is the most important thing in my life and I want to spend it wisely, that’s why I stopped going out on Thursday, Sunday and sometimes Friday when the newness of moving to a new city wears off.

My biggest focus is my dreams.

Things to be thankful about

Sometimes we compare ourselves to the top 1% of successful people and we don’t feel that we accomplished anything in life. I think it’s a very painful way to live and always comparing yourself to others and we forget our own achievements even if they’re small. I’m thankful I have health, I’m thankful I’m months away from paying my student loans and car loan, I’m thankful I have a cushy mid ~70k job (40hr), I’m thankful I have my parents, I’m thankful I’m moving to Dallas (I liked ft worth) in 7 months, I’m thankful I’m dating someone cool, I’m thankful I live alone and I’m thankful that I’m pursuing my dreams (at least half time). I’m thankful but not complacent, I want more of the good stuff and more requires hard work.

 

 

 

 

 

DSP class

Screen Shot 2016-07-11 at 7.22.49 PM.png

 

It’s been a while but I’m still in the struggle to learn audio DSP and last week I started my online DSP certification from UCSD and its three classes: DSP 1, Applied DSP and Wireless DSP. I’m currently taking DSP 1 and there’ s a lot of stuff that I already know from my signals classes from college, but this time is different because I have a purpose. When I was in college I was too distracted by girls, stress from other classes and my internships, but this time I have more time to dedicate most of my time to fully learn the concepts. Hopefully in the future I am able to write my own audio effects algorithms or at least to understand what’s under the hood. Sometimes I feel I’m not going fast enough, but I have to understand that things that are worth it takes YEARS. This past month I failed a lot to wake up at 5am, I was feeling too tired, but I am still on the game. “You only fail if you quit.”

In another note, I been learning more about core audio and I found a way to create a sequencer with musicSequence and AuGraph. Also I been playing with the new messages extension(ios 10) and I want to create a simple app that morphs your voice and sends it quick through the imessage app. It seems that the msmessage framework doesn’t work well right now, so I will wait until it’s released to the public and create that app.

Another goal that I want to achieve is to stop going out on Fridays and only go out on Saturdays, the problem about moving to a big city is distractions. Friends always invite me to places and since I live close to the bars and stuff I give up easily. My next apartment will be in a more calm area but close to downtown, because I’m moving in March 2017. Other thing that I’m happy with is about my debt is going down quick and I predict I will be debt free by April 2017. When I was in college I bought a bunch of stuff I didn’t need and now I’m paying for it plus interest. After being debt free I think I will have more confidence to start a risky idea and don’t be afraid of losing my job.

When you’re pursuing your dream you’re living the dream, enjoy the process.

 

Great introduction on how apple handles audio with core audio

https://www.mikeash.com/pyblog/friday-qa-2012-10-12-obtaining-and-interpreting-audio-data.html